Android All-in-one (immersive) status bar implementation

Source: Internet
Author: User

Note: The company development task adaptation is performed on the 4.4 release, so this adaptation is only tested on top of 4.4.

1, the main use of third-party open source projects Systembartint,github:https://github.com/jgilfelt/systembartint

2, according to Systembartint to carry out the study of sample, the main steps are as follows:

    1. Add the following code to the activity: 
 Public classMainactivityextendsbaseactivity {@Override Public voidSetcontentview () {Setcontentview (r.layout.activity_main); //Immersive status bar        Settranslucentstatus (); }

}
/*** Add android:fitssystemwindows= "true" property for the root layout of XML <br/>*/ protected voidSettranslucentstatus () {if(Build.VERSION.SDK_INT >=Build.version_codes. KITKAT) {Settranslucentstatus (true); } Systembartintmanager Tintmanager=NewSystembartintmanager ( This); Tintmanager.setstatusbartintenabled (true); Tintmanager.setstatusbartintresource (R.COLOR.STATUSBAR_BG);//the color required for the notification bar} @TargetApi (19) Private voidSettranslucentstatus (BooleanOn ) {Window win=GetWindow (); Windowmanager.layoutparams Winparams=win.getattributes (); Final intBITS =WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; if(ON) {Winparams.flags|=bits; } Else{winparams.flags&= ~bits; } win.setattributes (Winparams); }

Note: Some data say that the Settranslucentstatus () method needs to be placed after Setconentview (), and actually has no effect.

2. In the root layout of mainactivity, add:

Android:fitssystemwindows= "true"

3. If we add a custom TextView control to the middle of the layout and set the background color to be the same as the color in the Settranslucentstatus () method, we will find the effect as:

Among them, in the middle of StatusBar and TextView there will be a blank, this blank is Actionbar white, so, if the use of titlebar, you want to remove the actionbar display; If you use Actionbar, To set the background of the actionbar to the same color.

 Public class mainactivity  {@Override  Public void      Setcontentview () {          notitlebar ();      Setcontentview (R.layout.activity_main);     //  immersive status bar settranslucentstatus (); }             /**     * Does not display the     title bar * /     protectedvoid  Notitlebar () {        this. Requestwindowfeature (Window.feature_no_title);    }}  

The effect is as follows:

4. Since the code above GitHub is based on Gradle, the release source based on Eclipse is released below.

Android All-in-one (immersive) status bar implementation

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.