Transparent notification bar for Android development and implementation, and android notification bar

Source: Internet
Author: User

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"

.

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.