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