Use immersive status bar with three Android Codes

Source: Internet
Author: User

Use immersive status bar with three Android Codes

 

People who have used android phones know that the status bar on the top of the screen is black when android uses the app, even if it is not black, it is different from the color of the opened app. There is a feeling that it is not easy to adjust .~

I accidentally read the information about the immersive status bar today ~~ How can I miss it as a patient with obsessive-compulsive disorder?

Next we will start our Immersive status bar tour:

Code not advanced:

Immersive:

Non-immersive:

Hmm ~ Although the second image is fuzzy, you can also imagine that the first image looks better (~ )~.

Next we will talk about how to achieve the same effect as the first image:

The following methods are only applicable to Android 4.4 or later systems.

Android4.4, that is, api19 ~ So we create a new values-v19 under the res folder, and then create a new style. xml file.

Write the following code on the style:

Specify style as noactionbar and translucent

 

 
  
 

 

Then run the program and you can see that the status bar is the same color as the top of the app, however, if other content is written at the top of the layout file, the content in the layout file will overlap with the content on the status bar ~~ This is definitely not allowed.

Is there a solution?

Write the following two sentences on the layout file that uses the immersive status bar:

 

Then, write the following code in the layout file of the immersive status bar:

 

  android:clipToPadding="true"  android:fitsSystemWindows="true"

You can solve this problem ~

 

However, in some cases, you may find that the status bar color will be white or other colors after you write these two sentences ~ This is because the color of the Code is the same as that of the status bar.

That is to say, if the background color of a LinearLayout is red, when the immersive status bar is used, the status bar will also become red after the above two codes are written in the linearLayout.

 

 

We can see that there are actually three codes ~

 

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.