Toolbar+DrawerLayout
Toolbar是在 Android 5.0 开始推出的一个 Material Design 风格的导航控件,
以此来取代之前的Actionbar 。我们需要在工程中引入appcompat-v7的兼容包以便向下兼容,
使用android.support.v7.widget.Toolbar进行开发。在设计 Toolbar 的时候,
Google也留给了开发者很多可定制修改的余地,
这些可定制修改的属性在API文档中都有详细介绍,如:
1.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);去掉标题栏;
2.Toolbar.setLogo(),设置logo图片;
3.Toolbar.setTitle().设置标题;
4.Toolbar.setSubTitle()设置子标题;
5.Toolbar.setTitleTextColor(int color);设置标题文字颜色;
6.Toolbar.setSubtitleTextColor();设置子标题文字颜色;
7.setTitleMargin(int start, int top, int end, int bottom);设置标题margin值;
8.onCreateOptionsMenu,getMenuInflater().inflate(R.menu.menu,menu)
设置菜单在给Toolbar设置为actionbar时使用;
9.Toolbar.setOnMenuItemClickListener();Toolbar绑定menu监听;
10.Toolbar.inflateMenu(R.menu.menu)在Toolbar没有替换actionbar时使用;
11.setSupportActionBar(mToolbar);设置toolbar替换actionbar;
12.getLayoutInflater().inflate(R.layout.view_tv,bar);Toolbar添加自定义view
布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Day03.ToolBarTestActivity">
<android.support.v7.widget.Toolbar
app:navigationIcon="@drawable/ic_launcher_background"
app:subtitleTextColor="#4f5"
app:subtitle="副标题"
app:titleTextColor="#f40"
app:title="标题"
app:logo="@mipmap/ic_launcher_round"
android:background="#f95"
android:id="@+id/tb"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="100dp"
android:<