android P设置状态栏字体图标颜色

public void applyDark(DarkReceiver object) {} android


//安卓P会监听应用主题变化,亮色主题,设置字体和图标黑色, 黑色主题设置字体和图标等白色,经过onDarkChanged回调给ui。
//darkIntensity 为0f 则设置白色 ,为1f则设置黑色 app

interface DarkReceiver { 
    void onDarkChanged(Rect area, float darkIntensity, int tint); 
    } 
    
    
    public void onDarkChanged(Rect area, float darkIntensity, int tint) {
          mTextView.setTextColor(DarkIconDispatcher.getTint(area, this, tint)); 
    }
          
          
          
          
          
           int colorForeground = Utils.getColorAttr(getContext(), android.R.attr.colorForeground);
            float intensity = colorForeground == Color.WHITE ? 0f : 1f; 
            Rect tintArea = new Rect(0, 0, 0, 0); 
            
            
            
    darkIntensity 为0f 则设置白色 ,为1f则设置黑色 字体


    //应用中调用切换systemui 字体图标颜色,能够经过以下方式切换ui

    /**
     * Android 6.0 以上设置状态栏颜色
     */this

    int flag = 0;
    protected void setStatusBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {spa

            // 设置状态栏底色颜色
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().setStatusBarColor(getColor(R.color.text_color));get

            // 若是亮色,设置状态栏文字为黑色
            if (flag == 0) {
                flag = 1;
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            } else {
                flag = 0;
                getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
            }
        }it

    }mui

相关文章
相关标签/搜索