Android6.0状态栏图标原生反色操作

Android6.0状态栏图标反色操作

代码方式:

    public void setDarkStatusIcon(boolean bDark) {

       if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)

        {

       getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            View decorView =getWindow().getDecorView();

            if(decorView != null){

                int vis = decorView.getSystemUiVisibility();

                if(bDark){

                    vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;

                } else{

                    vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;

                }

                decorView.setSystemUiVisibility(vis);

            }

            getWindow().setStatusBarColor(Color.TRANSPARENT);

        }

}

在Activity里面的onCreate函数里面调用setDarkStatusIcon(bDark)

 

Xml方式:

1、 首先在manifest.xml文件中声明为android:theme="@style/AppTheme"

2、 在styles.xml文件里面添加如下:

<style name="AppTheme" parent="android:Theme.Material.Light">

       

        <item name="android:colorPrimaryDark">#fff5f5f5item>

        <item name="android:colorPrimary">#fff5f5f5item>

        <item name="android:windowLightStatusBar">trueitem>

        <item name="android:windowTranslucentStatus">falseitem>

        <item name="android:windowDrawsSystemBarBackgrounds">trueitem>

style>

 

你可能感兴趣的:(Android6.0状态栏图标原生反色操作)