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