在android5.0以后,添加了Material Design设计语言,这个确实是非常酷炫的、使用Toolbar代替了之前的Actionbar确实是灵活了很多。
之前我们只能在application或者activity中使用theme主题,但是在android 5.0中可以给View使用theme主题,这个View及其子View都会使用这个theme,给了我们设计一个很大的灵活性
- 给View添加theme的方法
android:theme=”你的theme”
例如:1
2
3
4
5
6
7<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/AppTheme.AppBarOverlay"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
上面代码的最后一个属性app:popupTheme:自定义我们弹出的菜单样式
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"代表的就是白底黑字
最后一个问题使用android:theme这个属性,在android3.0以上可以应用到View及其子View的,但是在android3.0以下只能应用到当前的View,是不能使子View起作用的,所有要用到该theme的View都要加上,这个切记,当然了android3.0以下的遗留机器已经很少了,如果你不用适配这个版本,你完全可以忽略这个。