基础
只兼容4.4以上的版本。
theme
通过theme进行配置。需要分为三类:v19以前,v19-v21以及v21以后。v19(无特殊设置)以前如下:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
values-v19,如下:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowActionBar">false</item><!--不能有actionbar-->
</style>
values-21如下:
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowActionBar">false</item>
</style>
为相应的activity配置该theme即可。另外Activity的根布局必须加上android:fitSystemWindows="true"。
JAVA
将配置的属性值通过java代码体现出来即可。
5.0以上
只能用于5.0以上。
decorView.getChildAt(1).setBackgroundColor(Color.YELLOW);//将状态栏背景改为黄色