Immersive status bar for Android 4.4
In Code settings:
if (VERSION. Sdk_int >= version_codes. KITKAT) { // transparent status bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_ Translucent_status); // Transparent navigation bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}
The direct call to the above 2 lines of code can be transparent, but you will find your view running up to the Actionbar, it's obvious
Google's intention is to make your view occupy the entire screen, and then the status bar and navigation bar transparent overlay on it is obviously not feasible.
is there a way to keep your view the same size?
There, you need to add two attributes to the activity's layout XML file:
<xmlns:android= "http://schemas.android.com/apk/res/android" Android : layout_width= "Fill_parent" android:layout_height= "Fill_parent" android:gravity= "Center_horizontal" android:fitssystemwindows= "true" android:cliptopadding= "true" android:orientation= " Vertical ">
The background of the status bar is the main background of your activity, and if actionbar, it will be very difficult to see,
The second way, is to set the theme property
Android:theme= "@android: Style/theme.devicedefault.light.noactionbar.translucentdecor" Android:theme= "@android: Style/theme.holo.light.noactionbar.translucentdecor "Android:theme=" @android: style/ Theme.Holo.NoActionBar.TranslucentDecor "
Copy code if you use a custom theme, simply add the following attribute in the values-19 file:
<name= "Appbasetheme" parent= "Android: Theme.Holo.Light.DarkActionBar "> <!--API Theme customizations can go. <item name= "Android:windowtranslucentstatus" >true</item> <item name= "Android: Windowtranslucentnavigation ">true</item></style>
Copy Code
Just said this use has limitations, but fortunately there is an open source thing
Https://github.com/jgilfelt/SystemBarTint
Using this open source library, you must open the transparent title bar
<name= "Appbasetheme" parent= "Android: Theme.Holo.Light.DarkActionBar "> <!--API Theme customizations can go. <item name= "Android:windowtranslucentstatus" >true</item> <item name= "Android: Windowtranslucentnavigation ">true</item></style>
Use this topic or call this code before Setcontentview
if (VERSION. Sdk_int >= version_codes. KITKAT) { // transparent status bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_ Translucent_status); // Transparent navigation bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}
Android 4.4 Immersive transparent status bar with navigation bar