通过代码更改槽口的背景颜色不起作用

时间:2019-05-08 07:24:20

标签: android

我尝试更改状态栏的颜色

if (Build.VERSION.SDK_INT >= 21) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(getResources().getColor(R.color.black));
        }

但是对于nocth diplay却不起作用。

1 个答案:

答案 0 :(得分:0)

尝试一下:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.colorPrimary));
    }

只需删除:window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);