Android realizes notification bar transparency

Source: Internet
Author: User

Notification bar Transparency Effect
The effect of the notification bar opacity is this :
But this effect is only supported in 4.4+
GetWindow (). Addflag (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

The demo is as follows:

    @Override    protectedvoidonCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);        setContentView(R.layout.activity_web_view);        }

and the XML layout file only adds a background color,

xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="Match_parent"android:layout_height="Match_parent"android:paddingleft="@dimen/activity_horizontal_margin"android:paddingright="@dimen/activity_horizontal_margin"android:paddingtop="@dimen/activity_vertical_margin"Android:background="@android: Color/holo_red_dark"Android:paddingbottom="@dimen/activity_vertical_margin"tools:context="Test.com.studiotest.WebViewActivity"> <webview android:layout_width="Match_parent"android:layout_height="Wrap_content"Android:id="@+Id/webview"android:layout_alignparentleft="true"android:layout_alignparentstart="true"android:layout_margintop="131DP"/></relativelayout> ""

Note the problem:
1, if the layout of the overall move up, you can get the height of the status bar, the overall layout of the activity to add a paddingtop, method:

int statusbarheight= 0;
int resourceId = Context.getresources (). Getidentifier ("Status_bar_height", "Dimen",
"Android");
if (ResourceId > 0) {
Statusbarheight= context.getresources (). Getdimensionpixelsize (ResourceId);
}
View.setpadding (0, statusbarheight, 0, 0);

2.与activity整体融合:然后在当前activity的布局文件中加入这两句话

Android:fitssystemwindows= "true"
Android:cliptopadding= "true"
"'

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android realizes notification bar transparency

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.