1.手机的页面各部分在android中表示的字段:

Android状态栏颜色 android设置状态栏图片_android

 

2.statusBarColor(状态栏)设置为图片:

  1.    在res—values—style中添加这样的样式:
//----------------------状态栏设置图片填充----------------
    <style name="ImageTranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowTranslucentStatus" tools:ignore="NewApi">false</item>
        <item name="android:windowTranslucentNavigation" tools:ignore="NewApi">true</item>
        <!--Android 5.x开始需要把颜色设置透明,否则导航栏会呈现系统默认的浅灰色-->
        <item name="android:statusBarColor" tools:ignore="NewApi">@android:color/transparent</item>
    </style>

windowTranslucentStatus:设置为true后,意思就是图片就可以拉伸到状态栏,并且状态栏为透明色。

windowTranslucentNavigation:设置为true后,意思就是图片就可以拉伸虚拟键盘,并且状态栏为透明色。

statusBarColor:设置状态栏颜色为透明色。

这样一设置后,就相当于填充整个屏幕了,不留一点空间了,如果你是列表的话,那么无所谓,并不影响操作和页面效果,如果你的是最下面有按钮的页面的话,你会发现这玩意就是一个坑啊,因为你的按钮填充到了下面,你根本按不到,而且如果你设置了透明属性的话,你会发现虚拟键和你最下面的按钮都重合在一起,具体效果:

 

Android状态栏颜色 android设置状态栏图片_状态栏_02

 

2.AndroidManifest.xml中设置

<activity android:name=".MainActivity"
          android:theme="@style/ImageTranslucentTheme" >
</activity>

3.activity_main.xml中的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity"

    android:fitsSystemWindows="true"
    android:background="@mipmap/ss">



</LinearLayout>

主要添加:

android:fitsSystemWindows="true"
      android:background="@mipmap/ss"
    这样就完成所有的步骤,成功实现上图效果,图片填充到状态栏和虚拟键盘。

3.状态栏设置固定的颜色

 

  1. 设置style.xml 的样式
<style name="ColorTranslucentTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="android:windowTranslucentStatus">false</item>
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:statusBarColor">@color/colorPrimaryDark</item>
</style>
  1. 在AndroidManifest.xml清单文件中的Activity中引用
<activity android:name=".MainActivity"
          android:theme="@style/ColorTranslucentTheme" >
</activity>

     3.在activity_main.xml 文件中添加

android:fitsSystemWindows="true"