Android system Change status bar font color _android

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.