Transparent notification bar for Android development and implementation, and android notification bar
This feature is supported by andorid4.4 and can be used at least by api19. That is to say, if the Android host is lower than 4.4, the immersion notification bar will be ineffective. The following describes how to use it, which is very simple.
/**
* The method for setting the notification bar is implemented in onCreate (). If it is added in onCreate () of the parent class, an immersive notification bar exists even if all inherits the parent class.
*/
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 );
}
Add android: fitsSystemWindows = "true" to the layout file"
.