您的位置:首页 > 移动开发 > Android开发

android顶部状态栏透明化,并释放空间

2017-03-03 10:32 267 查看
由于项目需求,需要将布局顶部放大状态栏的空间,类似这种



在网上搜索找到两种方法:

if (Build.VERSION.SDK_INT >= 19){
WindowManager.LayoutParams localLayoutParams = mActivity.getWindow().getAttributes();
localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
if (fmMain != null) { //fmMain:自定义的顶部导航条
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) fmMain.getLayoutParams();
layoutParams.setMargins(0, ChuangChuangApp.STATUSBARHEIGHT, 0, 0);//STATUSBARHEIGHT状态栏高度
fmMain.setLayoutParams(layoutParams); //设置顶部margin值
}

}

一般情况下margin值是可以不用设置的,这里因人而异;然后可以将导航条的背景设置成透明就可以达到效果了
另外一种方法:

if (Build.VERSION.SDK_INT >= 21) {
View decorView = getWindow().getDecorView();
fmMain.setBackgroundColor(Color.TRANSPARENT);
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
getWindow().setStatusBarColor(Color.TRANSPARENT);
}
这种方法是参考的郭霖大神的代码,具体链接地址: http://blog.csdn.net/guolin_blog/article/details/51763825
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: