設定miui狀態列黑白圖示顏色
阿新 • • 發佈:2018-12-25
其中public static void setStatusBarDarkMode(boolean darkmode, Activity activity) { //前版本miui設定顏色 Class<? extends Window> 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