Android immersion status bar and top status bar background color settings

Law one:

 

Many applications now refer to the immersive status bar, such as QQ, the effect is as follows:

 

 

 

 

This effect is very cool, in fact, the setup is very simple.

 

However, it should be noted that this effect can only be achieved in API 19 and above.

 

 If you want to achieve this effect in the interface Activity, the code is as follows:

  if(VERSION.SDK_INT>= VERSION_CODES.KITKAT) {
            //transparent status bar
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //transparent navigation bar
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }

 

VERSION_CODES.KITKAT is the name of API19. Only when the mobile phone system version is greater than 19 can the code in the judgment be executed to display the effect of the immersive status bar. 
At the same time, these lines of code should be written and executed before the setContentView(R.layout.XX); method.

 

 

 

 First post the renderings for comparison with the implementation process

 

 To remove the title bar, add the following code before setContentView(R.layout.XX);:

requestWindowFeature(Window.FEATURE_NO_TITLE);

码:requestWindowFeature(Window.FEATURE_NO_TITLE);

 renderings

The API is changed to 19 or above, the root tag adds a background color, and then

 

Law two:

 

Create a new values-v19 folder under the res directory, and create a new styles.xml file below with the following contents

Of course, this has to be added to the root tag of the layout file

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

 

If you don't add this code, the layout will be very close to the top, and it will not look good.

The application tag under AndroidManifest.xml references styles.xml in the values-v19 folder

The operation effect is the same.

 

Source code click to download

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326274061&siteId=291194637