Android has not changed much in the UI since 4.2, and 4.4 has just added the transparency status bar and navigation bar function.
So now I'm going to show you how to use this new feature to get your app to follow the trend, but if you don't care what it looks like,
Use this feature to develop a very beautiful UI, especially for the Google native system, the navigation bar at the bottom of the screen occupies a screen space, looks very uncomfortable
OK nonsense don't talk about it, start talking about technology,The first of these methods, 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 that your view ran to Actionbar, it is obvious that Google's intention is to make your view can occupy the entire screen, and then the status bar and navigation bar transparent overlay on the above is obviously not feasible.
is there a way to keep your view the same size?
there, you need to add two properties to this activity's layout XML file
- <linearlayout 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,
It turns out that Google does not provide a better solution, his transparent status bar and the application of the navigation bar is limited to full-screen reading text or playing games that kind of scene,
the second way,Yes Yes set 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 CodeIf you use a custom theme, simply add the following attribute in the values-19 file:
- <style 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
Use this topic
- <style 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>
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