状态栏变白色,状态栏图标变黑色。

来源:互联网 发布:湄公河大案 知乎 编辑:程序博客网 时间:2024/04/28 12:39

     前几天下的简书app,昨天玩手机发现它的状态栏是白色的,图标是黑色。用nexus6p和荣耀6试了下都是可以的。

     今天来查资料发现,M版以上是支持状态栏图标变色的。m版新增Flag:SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

     代码:

      public void setDarkStatusIcon(boolean bDark) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
            View decorView = getWindow().getDecorView();
            getWindow().setStatusBarColor(getResources().getColor(android.R.color.white));//这里对应的是状态栏的颜色,就是style中colorPrimaryDark的颜色
            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);
            }
        }
    }


public static final int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

Added in API level 23

Flag for setSystemUiVisibility(int): Requests the status bar to draw in a mode that is compatible with light status bar backgrounds.

For this to take effect, the window must request FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS but not FLAG_TRANSLUCENT_STATUS.

See Also
  • windowLightStatusBar
Constant Value: 8192 (0x00002000)
//For this to take effect, the window must request FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS but not FLAG_TRANSLUCENT_STATUS.
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 和FLAG_TRANSLUCENT_STATUS都是WindowManager.LayoutParams里面的flag,第一个我没有设置生效了,第二个与取的主题有关。我用的NoActionBar。第一个没有设置不知道为什么也生效了?




0 0
原创粉丝点击