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

相關文章
相關標籤/搜索