ANDROID implementation Notification Bar transparent method _android

Source: Internet
Author: User

This feature is andorid4.4 support, at least api19 can be used, that is, if the Android machine is less than 4.4, immersion notification bar is ineffective. Here is a brief introduction to the method used.

 /**
   * Set the notification bar This method is implemented in OnCreate (), if it is added in the parent class's OnCreate (), even if all inherited the parent class will have an immersion notification bar.
   *
/public void Initsystembar () {
    if Build.VERSION.SDK_INT >= build.version_codes. KitKat) {
      settranslucentstatus (true);
      Systembartintmanager Tintmanager = new Systembartintmanager (this);
      Tintmanager.setstatusbartintenabled (true);
      Tintmanager.setstatusbartintresource (r.color.red);
    }
  /**
   * Set the status of the notification bar
   * @param on
   /*
  @SuppressLint ("Inlinedapi") 
  private void Settranslucentstatus (Boolean on) { 
    Window win = This.getwindow (); 
    Windowmanager.layoutparams winparams = Win.getattributes (); 
    Final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 
    if (on) { 
      winparams.flags |= bits; 
    } else { 
      winparams.flags &= ~bits; 
    } 
    Win.setattributes (Winparams); 
  }

At the end of the layout file, add: Android:fitssystemwindows= "true"

can be achieved.

Android5.0 Full transparency status bar effect, the specific example code is as follows:

The code that implements this effect is as follows:

 public class Mainactivity extends activity {@SuppressLint ("Inlinedapi") @Override
    protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
    GetWindow (). Requestfeature (Window.feature_no_title); if (VERSION. Sdk_int >= version_codes.
      lollipop) {window window = GetWindow (); Window.clearflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS |
      WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); Window.getdecorview (). Setsystemuivisibility (View.system_ui_flag_layout_fullscreen | view.system_ui_flag_layout_hide_navigation |
      view.system_ui_flag_layout_stable);
      Window.addflags (WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
      Window.setstatusbarcolor (color.transparent);
    Window.setnavigationbarcolor (color.transparent);
  } setcontentview (R.layout.activity_main); }
}

The above code is not good, but also ask you to make a lot of heroes, and hope that this article to share the help.

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.