1. Frame
https://github.com/Zackratos/UltimateBar
UltimateBar.newImmersionBuilder()
.applyNav(true) // whether to apply to the navigation bar
.build(this)
.apply();
2. Combine
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//Set the status bar font color to dark
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);//Set the status bar font color to light color
Meizu uses the following method to set the font color of the status bar
/** * Set the status bar icon to dark color and Meizu specific text style * Can be used to determine whether it is a Flyme user * * @param window the window that needs to be set * @param dark Whether to set the status bar font and icon color to dark * @return boolean returns true on successful execution */ public static boolean FlymeSetStatusBarLightMode(Window window, boolean dark) { boolean result = false; if (window != null) { try { WindowManager.LayoutParams lp = window.getAttributes(); Field darkFlag = WindowManager.LayoutParams.class .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); Field meizuFlags = WindowManager.LayoutParams.class .getDeclaredField("meizuFlags"); darkFlag.setAccessible(true); meizuFlags.setAccessible(true); int bit = darkFlag.getInt (null); int value = meizuFlags.getInt(lp); if (dark) { value |= bit; } else { value &= ~bit; } meizuFlags.setInt(lp, value); window.setAttributes(lp); result = true; } catch (Exception e) { } } return result; }
MIUI uses the following method
/** * Set the status bar font icon to dark, MIUIV6 or above is required * * @param window the window that needs to be set * @param dark Whether to set the status bar font and icon color to dark * @return boolean returns true on successful execution */ public static boolean MIUISetStatusBarLightMode(Window window, boolean dark) { boolean result = false; if (window != null) { if (Build.BRAND != null && Build.BRAND.toLowerCase().trim().equals("xiaomi")) { String miuiVersionName = getSystemProperties("ro.miui.ui.version.name"); if (miuiVersionName != null && "v9".equals(miuiVersionName.trim().toLowerCase())) { window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR); return true; } } Class clazz = window.getClass(); try { int darkModeFlag = 0; Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); darkModeFlag = field.getInt(layoutParams); Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); if (dark) { extraFlagField.invoke(window, darkModeFlag, darkModeFlag);//The status bar is transparent and black font } else { extraFlagField.invoke(window, 0, darkModeFlag);//Clear the black font } result = true; } catch (Exception e) { e.printStackTrace (); } } return result; } public static String getSystemProperties(String key) { System.out.println("obtain key->" + key); String value = ""; try { Resources.getSystem(); Class<?> c = Class.forName("android.os.SystemProperties"); Method get = c.getDeclaredMethod("get", String.class); value = (String) get.invoke(c, key); } catch (Exception e) { e.printStackTrace (); System.out.println("get " + key + " error..."); value = ""; } return value; }