android设置状态栏的颜色

1.首先设置状态栏为透明。

2.再在布局文件中设置布局文件的背景颜色。

具体实现:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
         if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            }//设置状态栏透明
         requestWindowFeature(Window.FEATURE_NO_TITLE); //去掉标题栏
        setContentView(R.layout.activity_main);

值得注意的是:

要在布局的文件的跟节点加两个属性

android:clipToPadding="true"
    android:fitsSystemWindows="true"




方法2:设置 theme 属性

android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor"
android:theme="@android:style/Theme.Holo.Light.NoActionBar.TranslucentDecor"

android:theme="@android:style/Theme.Holo.NoActionBar.TranslucentDecor"

如果使用自定主题,只需在在 values-19 文件夹下添加以下属性

<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar" >
    <!-- API 19 theme customizations can go here. -->
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>

你可能感兴趣的:(android设置状态栏的颜色)