Black words on white background! Android Light status bar Black font mode (another)

Source: Internet
Author: User

Xiao bin want to do anything Ningchong cause far attention 2016.06.30 10:16* words 489 read 3234 comments 3 likes Objective

Because the damned undead design is wet, a set of white status bar UI is designed. Of course, on iOS can be adaptive, but Android is more troublesome, so has not been engaged. Recently saw an article on the White bottom black word! Android Light status bar Black font mode "The solution was mentioned, only to be enlightened."

MIUI 8.0


Screenshot_2016-06-30-09-39-51-101_com.linkit.lan.png lazy Typing, quoting the original author's words

Support for Android6.0 SYSTEM_UI_FLAG_LIGHT_STATUS_BAR can change the status bar icon to Gray.

and Android4.4 above system version can modify the status bar color, but only millet Miui, Meizu flyme and Android6.0 system can change the status bar text and icons for dark, the other system status bar text is white, replaced by light background words can not see.

Suitable for light-colored status bar when dark font is found, the underlying version of the Android6.0 MIUI system does not support SYSTEM_UI_FLAG_LIGHT_STATUS_BAR settings, or miui own dark font method. Three-party Android system to the bottom of the mess, but also make people headache. O__o

Import 1 (if you need to support Android4.4 's status bar discoloration, do not need to skip this step)

When build.gradle adding dependencies:

dependencies {    ‘com.readystatesoftware.systembartint:systembartint:1.0.3‘}

Or import this class directly:
https://github.com/jgilfelt/SystemBarTint/blob/master/library/src/com/readystatesoftware/systembartint/ Systembartintmanager.java

Import 2 (if you do not need to support Android4.4, remove the Systembartintmanager section)

Here to say, Miui's k,l,m three Android version I have tested, but because there is no Meizu's machine so has not been tested, also did not find Emui implementation method. The method of the original author is quoted here and integrated.

    White can be replaced by other light-coloured systems@TargetApi (build.version_codes. LOLLIPOP)PublicStaticvoidMystatusbar(Activity activity) {if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {if (Miuisetstatusbarlightmode (Activity.getwindow (),true)) {MIUIif (Build.VERSION.SDK_INT >= build.version_codes. LOLLIPOP) {5.0 Activity.getwindow (). Setstatusbarcolor (Color.White); }Elseif (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {4.4 Activity.getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); Systembartintmanager Tintmanager =New Systembartintmanager (activity); Tintmanager.setstatusbartintenabled (true); Tintmanager.setstatusbartintresource (Android. R.color.white); } }Elseif (Flymesetstatusbarlightmode (Activity.getwindow (),true)) {Flymeif (Build.VERSION.SDK_INT >= build.version_codes. LOLLIPOP) {//5.0 Activity.getwindow (). Setstatusbarcolor (Color.White);} else if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {//4.4 Activity.getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_ Translucent_status, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); Systembartintmanager Tintmanager = new systembartintmanager (activity); tintmanager.setstatusbartintenabled (true); Tintmanager.setstatusbartintresource ( Android. R.color.white); }} else if (Build.VERSION.SDK_INT >= build.version_codes. M) {//6.0 Activity.getwindow (). Setstatusbarcolor (Color.White); Activity.getWindow (). Getdecorview (). setsystemuivisibility (View.system_ui_flag_light_status_bar); } } }
    /** * Set status bar font icon is dark, need MIUIV6 above * *window to be set for @param windows *@param dark If the status bar font and icon color are set to dark *@return Boolean Successful execution returns true */PublicStaticBooleanMiuisetstatusbarlightmode(Window window,Boolean dark) {Boolean result =Falseif (Window! =NULL) {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 ( Int.class, int.class); if (Dark) {extraflagfield.invoke (window, Darkmodeflag, Darkmodeflag); //status bar transparent and black font} else {extraflagfield.invoke (window, 0, Darkmodeflag); //clear black font} result = true;} catch (Exception e) {}} return result;}            
    /** * Set status bar icons for dark and Meizu-specific text styles * can be used to determine if the user is FlyMe * *window to be set for @param windows *@param dark If the status bar font and icon color are set to dark *@return Boolean Successful execution returns true */PublicStaticBooleanFlymesetstatusbarlightmode(Window window,Boolean dark) {Boolean result =Falseif (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 (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 = Span class= "Hljs-keyword" >true; } catch (Exception e) {}} return result;}    
Reference articles

Original 1: Black word on white background! Android Light status bar black font mode
Original 2:android 6.0 status bar using gray text and icons

Black words on white background! Android Light status bar Black font mode (another)

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.