Android immersive Status Bar (Uniform Color Style of the status bar and app like ios)

Source: Internet
Author: User

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.

 

 

Related Article

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.