Android immersive Status Bar (Uniform Color Style of the status bar and app like ios)
This feature is supported by andorid4.4 and can be used at least by api19. The following describes how to use it, which is very simple:
Public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); // transparent status bar getWindow (). addFlags (WindowManager. layoutParams. FLAG_TRANSLUCENT_STATUS); // transparent navigation bar getWindow (). addFlags (WindowManager. layoutParams. FLAG_TRANSLUCENT_NAVIGATION );}}
// Transparent status bar getWindow (). addFlags (WindowManager. LayoutParams. FLAG_TRANSLUCENT_STATUS); // transparent navigation bar getWindow (). addFlags (WindowManager. LayoutParams. FLAG_TRANSLUCENT_NAVIGATION );
You only need to add the two lines of code to implement the immersive notification bar. Effect
Let's take a look at the layout of this interface:
It is a vertical stream layout, but in this case, there is still a problem. I add some text in textView, which is the green one. Let's take a look at the effect:
As you can see, the text and the status bar are overlapped. This is definitely not feasible. You need to add the following code:
android:fitsSystemWindows=true android:clipToPadding=true
When we look at the red part, the interface will still be immersed after the two lines are added, but the part of the status bar won't overlap any more, just like adding padding, for example:
As you can see, both the Green textView and the red button are moved down. The status bar is white and the color of the background linearLayout. Obviously, this is not what we want. We want the status bar to be the same color as the control we put on the top. At the same time, the control content does not repeat with the status bar. In fact, you just need to put the two lines of code on the control at the top of us. The Code is as follows:
Put the two lines of red code on the green textView. This will be the following effect:
This is what we want.