Android implementation of the immersion notification bar notification bar background color to follow the app navigation bar background color and change _android

Source: Internet
Author: User

Recently, many apps have met the immersion notification bar, the so-called Immersion notification bar: is used to navigate the various interface operating space in the context of the main program content, through the relative "invisible" interface to maximize the user's visual range to use the content itself.

The latest Android 4.4 system's Notification bar immersion mode is in the software when the notification bar and the top of the software color integration, so that not only the software and the system itself more integration. is the cell phone's notice bar color is no longer white, black simple two kinds of, I use the Millet 4 mobile phone, M 4 mobile phone with the software to support the immersion notification bar, for example: You can look at their QQ, the background color of its title is blue, then the notice bar will also become blue. Probably not before, but also recently supported.

I do not know when MIUI6 can be unified support. Here's how to get your app to support an immersion notification bar:

Daniel has already studied the GitHub and said how to achieve it:

First download Systembartint, the inside of the Systembartintmanager.java copy out into their own project, Determine and set the notification bar color in the actitvity OnCreate () method (color needs to be defined by the software's titlebar background)

Code One:

The code is as follows:

if (Build.VERSION.SDK_INT >= build.version_codes. KitKat) { 
settranslucentstatus (true); 
} 
Systembartintmanager Tintmanager = new Systembartintmanager (this); 
Tintmanager.setstatusbartintenabled (TRUE); 

The following is the status of setting the notification bar

@TargetApi 
private void Settranslucentstatus (Boolean on) { 
Window win = GetWindow (); 
Windowmanager.layoutparams winparams = Win.getattributes (); 
Final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 
if (on) { 
winparams.flags |= bits; 
} else { 
winparams.flags &= ~bits; 
} 
Win.setattributes (Winparams); 
}

This allows you to achieve the perfect immersion notification bar. Note that the system must be above 4.4. Little friends, come and have a try.

Code two:

The notification bar (notification) background color changes with the background color of the app navigation bar (top title).
This is also called the immersive status bar, which is proposed by Google in more than 4.4 of Android systems.
The style is as shown in the figure:

if (Build.VERSION.SDK_INT >= build.version_codes. KitKat) { 
GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); 

Then add the following in the XML layout file:

 android:cliptopadding= "false" android:fitssystemwindows= "true" 
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.