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 ~