Understanding of an immersive status bar

Source: Internet
Author: User

Android 4.4 has been added to the immersive version of this feature, I believe that the hands of the Andro is already Android

4.4 or later versions. An increasing number of applications have realized the effect of an immersive status bar.

Let's start by looking at a demo to familiarize yourself with the immersive style.

As you can see clearly in the diagram, the top of our project and the status bar of the phone are fused together. This is a very beautiful and natural way to behave.

In fact, it is not difficult to achieve this effect.

There are countless examples of immersive stories on the internet, but it is not misleading, it is too much junk code.

Not much to say, to see how I have achieved this effect.

First we add the corresponding activity in the layout file (e.g. example.xml) to achieve this effect.

The following code. Considering that Google has made a big change to the Android 5.0 version. So we're going to go in the code.

Line Award

Off, the immersive version of Android 4.4 and Android 5.0 later is not quite the same.

@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); //API >= 4.4 or API < 5.0 full transparent status bar        if(Build.VERSION.SDK_INT >=Build.version_codes.          KITKAT) {GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); }            //API >=5.0 fully transparent implementation        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 are in the layout file (e,g. Example.xml) Add the following code below

< relativelayout ... >                ------> Outermost  ...   </ Relativelayout >              ------> Outermost layer with  android:cliptopadding= "true"  android:fitssystemwindows= "true" in the outermost layer  

At this point, our immersive style is realized. The amount of code is very small and easy to understand.

For more programming knowledge, please follow my Sina Weibo: @ Wu Tianhao Tnnowu

Understanding of an immersive status bar

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.