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);
在网上搜索找到两种方法:
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
相关文章推荐
- Android顶部状态栏透明化并释放空间的两种实现方法
- Android学习--系统顶部状态栏透明化
- Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android 4.0平板底部状态栏的方法)
- Android 在程序运行时,有若干个activity,怎么在退出这个Activity是,释放掉它所占用的运行空间
- 获取android顶部状态栏高度的两种方式
- Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android 4.0平板底部状态栏的方法)
- 3种Android隐藏顶部状态栏及标题栏的方法
- android去掉layout顶部的阴影(状态栏下边的阴影)
- android如何实现类似ios点击状态栏回到顶部功能
- android 去掉顶部状态栏
- android 自定义顶部状态栏颜色
- 当 Activity 以全屏模式运行时,如何允许 Android 系统状态栏在顶层出现,而不迫使 Activity 重新布局让出空间?
- android 4.0将SystemUI状态栏由顶部移到底部(一)
- Android系统释放用户空间小结
- 如何清理释放 Android 手机内存空间
- Android之——杀死选中的进程(释放进程占用的空间)
- 把android 4.2平板的状态栏从底部挪到顶部
- 当 Activity 以全屏模式运行时,如何允许 Android 系统状态栏在顶层出现,而不迫使 Activity 重新布局让出空间
- Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android 4.0平板底部状态栏的方法)
- android 顶部状态栏遮盖