Achieve immersive Android concerning the status bar

  This article is a record after their mission to achieve it, the effect is achieved, and want to write it down, you need a friend for reference.

  First, the first to tell you about what is immersive status bar (Note: This feature is compatible with the lowest API 19, that is Android 4.4 (Kitkat)).

        In layman's immersive status bar is the default Android Activity in the status bar changes to develop color.

         Original:

       

   Renderings:

 Careful small partners will find that the color rendering in the status bar has changed, and this is the effect of immersion is achieved the status bar.

 two. Here I achieved a major change in the status bar of the Activity of two types, one is to change the status bar of the Android source raw Activity, and the other one is to change the mixed use development Activity H5 page of the status bar

     1. First look at changing the status bar of the Android source raw Acitivity approach:

       1) New values-v19 and values-v21 of style.xml under res / values ​​android project, the contents of the file are:

         v19:

     v21:

              

2) After doing the above work, all added to change the layout of the status bar Activity root file layout: android: fitsSystemWindows = "true", as shown below:

    

3) bug began to write it! (Writing code) hee hee

Since a project may have a lot of Activity needed to achieve this effect, it is recommended you to package it into a utility class, and then call it in the Activity needed, the code is as follows:

            Well, I write to you your job basically is complete, and that the next step is to call your tools in your package to get in, oh Activity

4) the calling code as follows:

  


  This type of precipitation easy to get the status bar effect, but the difficult thing here, now popular mixed-use development, namely Activity page by page to load H5, that he was born and active correspondence

   The layout of the document, that the above not so that this trick, then how should we do it? Do not worry, slowly take you into the pit, (* ^ __ ^ *) hee hee ......

First, for use as H5 Activity page layout, he did not setContentView (R.layout.XX) this way, then we also have the means to deal with him. For details, please refer to the following to complete oh

       1) Use SystemBarTintManager to achieve, first of all in your project to introduce SystemBarTintManager, introduced in two ways, the first to gitHub download this compressed package, into your project, make your project relies libary library ;

The second: add this code directly in your build.gradle, and then re-build the project to look,

    

2 ) the operation is the same as in the res / values / v19 to, android source code and students

3) Start adding the code in the project:

So you can easily get mixed precipitation type state development Activity status bar oh. for reference only.

     

Released eight original articles · won praise 4 · views 10000 +

Guess you like

Origin blog.csdn.net/honey_angle_first/article/details/72910174