http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0303/2522.html(转载)
Toolbar介绍
ActionBar由于其设计的原因,被限定只能位于活动的顶部。从而不能实现一些Material Design的效果,因此官方现在已经不再建议使用Actionbar了。Toolbar的强大之处在于,它不仅继承了Actionbar的所有功能,而且灵活性很高,可以配合其他控件来完成一些MaterialDesign的效果。
DrawerLayout介绍
DrawerLayout是在Slidingmenu出现之后的产物。
NavigationView介绍
NavigationView是Design Support库中提供的一个控件,因此使用时需要把这个库引入到项目中才行。
打开app/build.gradle文件,在dependencies闭包中添加如下内容
compile 'com.android.support:design:24.2.1'
compile 'de.hdodenhof:circleimageview:2.1.0'
第一行是Design Support库,第二行是一个开源项目CircleImageView,该项目可用来轻松实现图片原型化的功能,它的项目地址是https://github.com/hdodenhof/CircleImageView
1.toolbar.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <android.support.v7.widget.Toolbar 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 android:id="@+id/toolbar_custom" 6 android:layout_width="match_parent" 7 android:layout_height="?attr/actionBarSize" 8 android:background="?attr/colorPrimary" 9 android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 10 app:popupTheme="@style/Theme.AppCompat.Light" 11 > 12 </android.support.v7.widget.Toolbar>