Android immersive status bar, color changing status bar, transparent status bar, modification of status bar color and transparency

Source: Internet
Author: User

Android immersive status bar, color changing status bar, transparent status bar, modification of status bar color and transparency

First, I want to distinguish between the immersive Status Bar and the color-changing status bar.

Immersive Status BarIt indicates that the status bar is hidden. After you perform operations on your fingers, the status bar is displayed. For example, when you play a video, the status bar is hidden, but when you click the screen, the status bar is displayed. For example, when reading a text reader, the status bar is displayed in full screen mode and then sliding down or down the screen. The virtual key and status bar appear, but it is directly covered in the program text, which is called the immersive status bar.
The status bar is usually the same color or transparent as the navigation bar. It refers to the color-changing status bar or transparent status bar.
For more information about these two concepts, see http://www.androidchina.net/3520.html.

After v19 (4.4), android: windowTranslucentStatus is supported. The transparent status bar is displayed. After v21 (5.0), the color of the status bar is changed. You can set the color of the status bar as needed.
These two new features help us quickly achieve the same color of the status bar after 4.4 and the navigation bar of the app.

The color-changing navigation bar is implemented through theme in styles:

Next we will define the topic BaseAppTheme, which is inherited from the AppTheme defined above. base topic, which defines three colors, respectively specifying the color of the status bar, toolbar, and key controls on the page (color defined by yourself ).

 

For the meanings of each color attribute in an AppCompat topic, refer


Then define an AppTheme that inherits from BaseAppTheme,

 

5.0: New values-v21 \ styles. xml"

Define the AppTheme applicable to the 5.0 System and the color-changing status bar proposed in the 5.0 system. Therefore, we only need to define an AppTheme to inherit the BaseAppTheme Code as follows:

 

The running result is that on the 4.4 system, the display is completely normal, while on the 5.0, the toolbar is normally displayed transparent, but the status bar is displayed gray transparent
4.4 system:

5.0 system:

The reason should be that the 4.4 system supports the transparent status bar, so you only need to set the status bar color to transparent to achieve the effect.
In contrast, 5.0 supports the color-changing status bar, and the result is different from our expectation. We should handle the following:

Set in the code to determine if the sdk is greater than or equal to 5.0, execute the following code

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);
}

After running, the system can achieve transparent effects on the 4.4 and 5.0 systems, as shown below:

Source code download


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.