如下图所示,能够设置颜色的部分有4个。分别是:状态栏,app bar,navigationbarcolor,窗体背景色.
状态栏透明色:
1,在style主题样式中添加 android:windowTranslucentStatus 属性;并吧该style设置为activity的theme。
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowTranslucentStatus" tools:targetApi="19">true</item>
</style>
</resources>
2,在layout中设置 android:fitsSystemWindows 属性,如下。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/id_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#009688"
android:minHeight="?attr/actionBarSize"/>
</LinearLayout>
如此这般,状态栏颜色从原来的黑色,变为透明色了
app bar 背景色设置:
如上段代码中的android:background="#009688",即可实现toolbar的背景色设置了。很简单吧
navigationbarcolor背景色设置:
navigationbarcolor是5.0以上系统才会有的,所以相关属性的设置需要在文件(res/values-v21/styles.xml)中。
<resources>>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:navigationBarColor">#009688</item>
</style>
</resources>
是不是也很简单?
窗体背景色设置:
窗体背景色的设置就更加简单了,只需要在style.xml文件的如下设置,并吧该style设置为activity的theme即可。
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#00aaff</item>
</style>
</resources>