Change the color of the status bar when Android sets the immersive status bar (available only for MIUI V6)

Source: Internet
Author: User

Android supports the use of immersive State in API 19 and above, but under MIUI V6 if the extended color is lighter, the text in the status bar will not be legible.

The immersive status bar is supported on Android4.4 devices, only add values-v19/styles.xml under Add

< Style  name  = "Appbasetheme"  parent  = "@style/theme.appcompat.light.noactionbar"  >  <item  name  = "android  :windowtranslucentnavigation " > false  </item  ><item  name  = "android  : Windowtranslucentstatus " >true  </item   </style ;   

Then add properties android:fitsSystemWindows="true" to the controls that you can extend
It's a broad-based.
However, under MIUI V6 if the extended color is lighter, the text in the status bar will not be legible. There is a gray area of the gradient on the other ROM.

MIUI provides a new solution, the status bar on the MIUI V6 supports both gray-black and white font colors, and developers can directly set the text color of the current interface status bar.

Specific code:

/** * only supports MIUI V6 * @param context * @param type 0--only need status bar transparent 1-status bar transparent and black font 2-clear black font */      Public Static void Setstatusbartextcolor(Activity context,intType) {if(!ismiuiv6 ()) {DEBUGLOG.D ("IsMiUIV6:"+false);return; } DEBUGLOG.D ("IsMiUIV6:"+true);        window window = Context.getwindow (); Class clazz = Window.getclass ();Try{intTranceflag =0;intDarkmodeflag =0; Class layoutparams = Class.forName ("Android.view.miuiwindowmanager$layoutparams"); Field field = Layoutparams.getfield ("Extra_flag_status_bar_transparent");            Tranceflag = Field.getint (layoutparams); field = Layoutparams.getfield ("Extra_flag_status_bar_dark_mode");            Darkmodeflag = Field.getint (layoutparams); Method Extraflagfield = Clazz.getmethod ("Setextraflags",int. class,int. Class);if(Type = =0) {Extraflagfield.invoke (window, Tranceflag, Tranceflag);//Only need status bar transparent}Else if(Type = =1) {Extraflagfield.invoke (window, Tranceflag | darkmodeflag, Tranceflag | darkmodeflag);//status bar transparent and black font}Else{Extraflagfield.invoke (window,0, Darkmodeflag);//Clear Black font}        }Catch(Exception e) {        }    }Private Static FinalString Key_miui_version_name ="Ro.miui.ui.version.name";Private Static Boolean isMiUIV6() {Try{FinalBuildproperties prop = Buildproperties.newinstance (); String name = Prop.getproperty (Key_miui_version_name,"");if("V6". Equals (name)) {return  true; }Else{return false; }//Return Prop.getproperty (Key_miui_version_code, NULL)! = NULL//| | Prop.getproperty (KEY_MIUI_VERSION_NAME, NULL)! = NULL//| | Prop.getproperty (key_miui_internal_storage, NULL)! = NULL;}Catch(FinalIOException e) {return false; }    }

Change the color of the status bar when Android sets the immersive status bar (available only for MIUI V6)

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.