Understanding of immersive status bar and immersive Status Bar

Source: Internet
Author: User

Understanding of immersive status bar and immersive Status Bar

Android 4.4 has added the immersive feature. I believe that the Android machine in your hands is already Android.

4.4 or higher. More and more applications have achieved the immersive status bar effect.

Let's take a look at a Demo to familiarize ourselves with immersion.

 

 

The figure clearly shows that the top of our project is integrated with the mobile phone status bar. This is very beautiful and natural.

 

In fact, implementing this effect is not difficult.

 

There are countless immersive examples on the Internet, but there are not too many spam code to mislead new people.

 

Let's not talk about it much. Let's see how I achieve this effect.

 

First, add the following content to the Activity corresponding to the layout file (e.g. example. xml) to implement this effect.

The following code. Considering that Google has made major changes to Versions later than Android 5.0. So we need to enter

Row Determination

Disconnected. The immersion style of Android 4.4 is different from that of Android 5.0 and later versions.

 

@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // API> = 4.4 or API <5.0 transparent status bar if (Build. VERSION. SDK_INT> = Build. VERSION_CODES.KITKAT) {getWindow (). addFlags (WindowManager. layoutParams. FLAG_TRANSLUCENT_STATUS);} // API> = 5.0 fully transparent if (Build. VERSION. SDK_INT> = Build. VERSION_CODES.LOLLIPOP) {Window window = getWindow (); Window. clearFlags (WindowManager. layoutParams. FLAG_TRANSLUCENT_STATUS); window. getDecorView (). setSystemUiVisibility (View. SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View. SYSTEM_UI_FLAG_LAYOUT_STABLE); window. addFlags (WindowManager. layoutParams. FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window. setStatusBarColor (Color. TRANSPARENT );}}

Then we add the following code in the layout file (e, g. example. xml ):

<RelativeLayout...> ------> outermost layer... </RelativeLayout> ------> append android: clipToPadding = "true" android: fitsSystemWindows = "true" to the outermost layer"

So far, our immersion is achieved. The code is small and easy to understand.

 

 

For more programming knowledge, please pay attention to my Sina Weibo: @ Wu tianhao TnnoWu

 

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.