With the development of the Times, Android's status bar is not a black one, after Android4.4 we can modify the status bar color or let our own view to extend under the status bar. We can do more customization, but sometimes we use a tint of color such as white, because the status bar above the text is white, so the text on the status bar can not see. Therefore, this article provides some solutions, which can be miui6+,flyme4+,android6.0+ support to toggle the status bar text color is dark color.
Modify MIUI
public static Boolean Setmiuistatusbardarkmode (activity activity, Boolean Darkmode) {
class<? extends window> Clazz = Activity.getwindow (). 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);
Extraflagfield.invoke (Activity.getwindow (), Darkmode darkmodeflag:0, darkmodeflag);
return true;
} catch (Exception e) {
e.printstacktrace ();
}
return false;
}
The solution provided above for the millet official, mainly for the MIUI built-in mode to modify the status bar, support dark and light two modes.
Modify FlyMe
public static Boolean Setmeizustatusbardarkicon (activity activity, Boolean dark) {Boo
Lean result = false;
if (activity!= null) {try {windowmanager.layoutparams LP = Activity.getwindow (). 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);
Activity.getwindow (). SetAttributes (LP);
result = true;
The catch (Exception e) {}} return result; }
Using the same way as Miui
Modify android6.0+
Android 6.0 started, Google officially provided support to configure Android:windowlightstatusbar in the style attribute
Then, when set to True, the text color of the statusbar is dimmed when the statusbar background color is a tint, and is the same as false.
<style name= "Statusbarstyle" parent= "@android: Style/theme.devicedefault.light" >
<item name= "Android: Statusbarcolor "> @color/status_bar_color</item>
<item name=" Android:windowlightstatusbar "> False</item>
</style>
This is the Android system to change the status bar font color code, I hope to help you learn.