首页 > 其他 > 详细

Toolbar

时间:2017-04-11 09:47:25      阅读:185      评论:0      收藏:0      [点我收藏+]

1.在activity的layout中添加toolbar

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     tools:context="com.mazingtec.mazing.Hall">
 8 
 9     <android.support.design.widget.AppBarLayout
10         android:layout_width="match_parent"
11         android:layout_height="wrap_content">
12 
13         <android.support.v7.widget.Toolbar
14             android:id="@+id/toolbar"
15             android:layout_width="match_parent"
16             android:layout_height="?attr/actionBarSize"
17             android:background="@color/primary_dark_material_dark" />
18 
19     </android.support.design.widget.AppBarLayout>
20 
21     <include layout="@layout/content_main" />
22 
23 </android.support.design.widget.CoordinatorLayout>

 

2.新建一个layout来放主要内容

1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3     android:orientation="vertical" android:layout_width="match_parent"
4     android:layout_height="match_parent">
5 
6 </LinearLayout>

 

3.代码中启用toolbar

1 Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
2         toolbar.setTitle("Hall");
3         setSupportActionBar(toolbar);

 

4.添加其他需要的按钮

 

Toolbar

原文:http://www.cnblogs.com/mazing/p/6691811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!