With the development of the times, the status bar of Android is not black. After Android 4.4, we can modify the color of the status bar or extend our own View below the status bar. We can make more customizations, but sometimes we use light colors such as white. Since the text on the status bar is white, the text on the status bar cannot be seen clearly. Therefore, this article provides some solutions, which can be MIUI6+, Flyme4+, and Android 6.0+ supports switching the text color of the status bar to dark.
Modify MIUI
public static boolean setMiuiStatusBarDarkMode(Activity activity, boolean darkmode) { Class<? extends Window> clazz = ().getClass(); try { int darkModeFlag = 0; Class<?> layoutParams = ("$LayoutParams"); Field field = ("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); darkModeFlag = (layoutParams); Method extraFlagField = ("setExtraFlags", , ); ((), darkmode ? darkModeFlag : 0, darkModeFlag); return true; } catch (Exception e) { (); } return false; }
The above solution provided by Xiaomi is mainly built-in modes for MIUI that can modify the status bar, and supports two modes: Dark and Light.
Modify Flyme
public static boolean setMeizuStatusBarDarkIcon(Activity activity, boolean dark) { boolean result = false; if (activity != null) { try { lp = ().getAttributes(); Field darkFlag = .getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); Field meizuFlags = .getDeclaredField("meizuFlags"); (true); (true); int bit = (null); int value = (lp); if (dark) { value |= bit; } else { value &= ~bit; } (lp, value); ().setAttributes(lp); result = true; } catch (Exception e) { } } return result; }
Similar to using a similar method to miui
Modify Android 6.0+
Starting from Android 6.0, Google has provided support, and configure android:windowLightStatusBar in style attribute
That is, when set to true, when the background color of statusbar is light, the text color of statusbar will turn gray, the same is true when it is false.
<style name="statusBarStyle" parent="@android:style/"> <item name="android:statusBarColor">@color/status_bar_color</item> <item name="android:windowLightStatusBar">false</item> </style>
The above is the relevant code for changing the font color of the status bar in the Android system. I hope it will be helpful to everyone's learning.