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