Android 4.4 immersive transparent status bar and navigation bar, android4.4

Source: Internet
Author: User

Android 4.4 immersive transparent status bar and navigation bar, android4.4

The UI of the Android system has not changed much since 4.2, and 4.4 Only adds the transparent status bar and navigation bar function,




Now I will explain how to use this new feature so that your app can follow the trend. Of course, if you don't care about the appearance,
This feature can be used to develop a very beautiful UI. Especially for google's native system, the navigation bar at the bottom of the screen occupies a piece of screen space, and it looks uncomfortable.



Okay. Let's talk about the technology. The first method is to set it in the Code:

  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. }
Directly calling the above two lines of code can be transparent, but you will find that your view goes to the actionbar. Obviously, google's intention is to make your view occupy the entire screen, then the status bar and navigation bar are transparently covered above, which is obviously not feasible.
Is there any way to keep your view in the original size?
Yes. You need to add two attributes to the layout xml file of the activity.
  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">
In this way, the background of the status bar is the main background of your activity. If the actionbar is present, it will be ugly,

Facts have proved that google does not provide a better solution. Its transparent status bar and navigation bar are limited to scenarios such as reading text in full screen or playing games,


The second method is to set the theme attribute.

  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 the Code. If you use a custom topic, you only need to add the following attributes to the values-19 file:
  1. <Style name = "AppBaseTheme" parent = "android: Theme. Holo. Light. DarkActionBar">

  2. <! -- API 19 theme customizations can go here. -->
  3. <Item name = "android: windowTranslucentStatus"> true </item>
  4. <Item name = "android: windowTranslucentNavigation"> true </item>
  5. </Style>
Copy code
I just mentioned that this application has limitations, but fortunately there is an open source thing.
Https://github.com/jgilfelt/SystemBarTint


To use this open-source library, you must enable the transparent title bar.

Use this topic

  1. <Style name = "AppBaseTheme" parent = "android: Theme. Holo. Light. DarkActionBar">

  2. <! -- API 19 theme customizations can go here. -->
  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. }




Related Article

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.