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

来源:互联网 发布:c 开发 gprs源码 编辑:程序博客网 时间:2024/06/06 18:06

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文件里面添加如下:

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

        <!-- All customizations that are NOT specific to a particular API-levelcan go here. -->

        <itemname="android:colorPrimaryDark">#fff5f5f5</item>

        <itemname="android:colorPrimary">#fff5f5f5</item>

        <itemname="android:windowLightStatusBar">true</item>

        <itemname="android:windowTranslucentStatus">false</item>

        <itemname="android:windowDrawsSystemBarBackgrounds">true</item>

</style>

 

0 0