android设置状态栏亮色、暗色

 

/*
     *   参考:https://blog.csdn.net/a940659387/article/details/79747479
     */
    public void setStatusBarWordBlack(Dialog dialog) {
        Window window = dialog.getWindow();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // 设置状态栏底色颜色
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.setStatusBarColor(Color.TRANSPARENT);
//            if (isLightColor(color)) {
            //设置状态栏文字为黑色
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//            } else {
            //设置状态栏文字为亮色
//                window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
//            }
        }
    }

 

posted @ 2020-11-18 18:05  野生野鸡码农  阅读(776)  评论(0编辑  收藏  举报