Android ToolBar 解析与应用(三)状态栏,toolbar,窗口背景,底部导航条颜色设置,

        如下图所示,能够设置颜色的部分有4个。分别是:状态栏,app bar,navigationbarcolor,窗体背景色.

Android ToolBar 解析与应用(三)状态栏,toolbar,窗口背景,底部导航条颜色设置,_第1张图片

状态栏透明色:

        1,在style主题样式中添加 android:windowTranslucentStatus 属性;并吧该style设置为activity的theme。


  1. <resources xmlns:tools="http://schemas.android.com/tools">
  2. <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  3. <item name="android:windowTranslucentStatus" tools:targetApi="19">trueitem>
  4. style>
  5. resources>

        2,在layout中设置  android:fitsSystemWindows 属性,如下。


  1. xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:fitsSystemWindows="true"
  6. android:orientation="vertical">
  7. <android.support.v7.widget.Toolbar
  8. android:id="@+id/id_toolbar"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:background="#009688"
  12. android:minHeight="?attr/actionBarSize"/>
  13. LinearLayout>

如此这般,状态栏颜色从原来的黑色,变为透明色了


app bar 背景色设置:

        如上段代码中的android:background="#009688",即可实现toolbar的背景色设置了。很简单吧


navigationbarcolor背景色设置:

        navigationbarcolor是5.0以上系统才会有的,所以相关属性的设置需要在文件(res/values-v21/styles.xml)中。


  1. <resources>>
  2. <style name="AppTheme" parent="AppBaseTheme">
  3. <item name="android:navigationBarColor">#009688item>
  4. style>
  5. resources>

        是不是也很简单?


窗体背景色设置:

        窗体背景色的设置就更加简单了,只需要在style.xml文件的如下设置,并吧该style设置为activity的theme即可。


  1. <resources xmlns:tools="http://schemas.android.com/tools">
  2. <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
  3. <item name="android:windowBackground">#00aaffitem>
  4. style>
  5. resources>




你可能感兴趣的:(Android开发之路)