设置miui状态栏黑白图标颜色

 
public static void setStatusBarDarkMode(boolean darkmode, Activity activity) {
        //前版本miui设置颜色
        Class clazz = activity.getWindow().getClass();
        try {
            Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            int darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            extraFlagField.invoke(activity.getWindow(), darkmode ? darkModeFlag : 0, darkModeFlag);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //新版本miui 颜色设置

        int   flag =  ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR &( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

        if (darkmode) {
//            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            flag = View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        }
        activity.getWindow().getDecorView().setSystemUiVisibility(flag);
    }
其中
 
  
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
为自定义状态栏属性(适配安卓6.0)。
 
  
参考:https://dev.mi.com/doc/p=10416/index.html

你可能感兴趣的:(Android,miui)