Android 4.4 Immersive transparent status bar with navigation bar

Source: Internet
Author: User

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:

  1. if (VERSION. Sdk_int >= version_codes. KITKAT) {
  2. Transparent status bar
  3. GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  4. Transparent navigation bar
  5. GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
  6. }
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
  1. <linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
  2. Android:layout_width= "Fill_parent"
  3. android:layout_height= "Fill_parent"
  4. Android:gravity= "Center_horizontal"

  5. Android:fitssystemwindows= "true"
  6. Android:cliptopadding= "true"

  7. 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

    1. Android:theme= "@android: Style/theme.devicedefault.light.noactionbar.translucentdecor"
    2. Android:theme= "@android: Style/theme.holo.light.noactionbar.translucentdecor"
    3. 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:
  1. <style name= "Appbasetheme" parent= "Android:Theme.Holo.Light.DarkActionBar" >

  2. <!--API Theme customizations can go. -
  3. <item name= "Android:windowtranslucentstatus" >true</item>
  4. <item name= "Android:windowtranslucentnavigation" >true</item>
  5. </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

  1. <style name= "Appbasetheme" parent= "Android:Theme.Holo.Light.DarkActionBar" >

  2. <!--API Theme customizations can go. -
  3. <item name= "Android:windowtranslucentstatus" >true</item>
  4. <item name= "Android:windowtranslucentnavigation" >true</item>
  5. </style>

or call this code before setcontentview.


  1. if (VERSION. Sdk_int >= version_codes. KITKAT) {
  2. Transparent status bar
  3. GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
  4. Transparent navigation bar
  5. GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
  6. }




Android 4.4 Immersive transparent status bar with navigation 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.