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.