dialog即使设置全屏了,但还是有状态栏占用高度这;
直接将下面这行代码放到你的dialog中即可
1
2
3
4
5
6
7
8
9
10
11
|
@Override protected void onStart() { super .onStart(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_FULLSCREEN; this .getWindow().getDecorView().setSystemUiVisibility(uiOptions); } |
顺便说下自定义dialog宽高:
1
2
3
4
|
WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.width = width; attributes.height = height; getWindow().setAttributes(attributes); |
添加两个基本的style
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!--普通dialog样式--> <style name= "customerDialog" parent= "@android:style/Theme.Dialog" > <item name= "android:windowFrame" >@null</item> <item name= "android:windowIsFloating" >true</item> <item name= "android:windowIsTranslucent" >true</item> <item name= "android:windowNoTitle" >true</item> <item name= "android:background" >@android:color/ transparent </item> <!-- <item name= "android:windowAnimationStyle" >@android:style/Animation.Translucent</item> --> <item name= "android:windowBackground" >@android:color/ transparent </item> <item name= "android:windowSoftInputMode" >stateHidden|adjustPan</item> </style> <!--透明背景dialog样式--> <style name= "TransparentDialogStyle" parent= "@android:style/Theme.Dialog" > <item name= "android:windowBackground" >@android:color/ transparent </item> <item name= "android:windowNoTitle" >true</item> <item name= "android:backgroundDimEnabled" >false</item> </style> |
补充知识:Android关于全屏设置和隐藏状态栏、沉浸式状态栏的总结
1.全屏和推出全屏
实现全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
有一个View.setLayoutparams的方法,注意这个LayoutParams跟的不是自身的LayoutParams而是父容器的layoutParams
退出全屏
1
2
3
4
|
final WindowManager.LayoutParams attrs = getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setAttributes(attrs); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); |
2.隐藏状态栏
getWindow().getDecorView().setSystemUiVisibility(View.INVISIBLE);
参数:
View.SYSTEM_UI_FLAG_VISIBLE:显示状态栏,Activity不全屏显示(恢复到有状态的正常情况)。
View.INVISIBLE:隐藏状态栏,同时Activity会伸展全屏显示。
View.SYSTEM_UI_FLAG_FULLSCREEN:Activity全屏显示,且状态栏被隐藏覆盖掉。
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN:Activity全屏显示,但状态栏不会被隐藏覆盖,状态栏依然可见,Activity顶端布局部分会被状态遮住。
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
View.SYSTEM_UI_LAYOUT_FLAGS:效果同View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:隐藏虚拟按键(导航栏)。有些手机会用虚拟按键来代替物理按键。
View.SYSTEM_UI_FLAG_LOW_PROFILE:状态栏显示处于低能显示状态(low profile模式),状态栏上一些图标显示会被隐藏。
3.沉浸式状态栏(android4.4开始引进)
(1).通过SystemBarTintManager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus( true ); SystemBarTintManager tintManager = new SystemBarTintManager( this ); tintManager.setStatusBarTintEnabled( true ); tintManager.setStatusBarTintResource(R.color.color_top_bg); // 通知栏所需颜色 } @TargetApi ( 19 ) private void setTranslucentStatus( boolean on) { Window win = getWindow(); WindowManager.LayoutParams winParams = win.getAttributes(); final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; // WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION if (on) { winParams.flags |= bits; } else { winParams.flags &= ~bits; } win.setAttributes(winParams); } |
(2).通过顶部增加同ActionBar颜色的view(如果设置后出现tittlebar则在清单文件里面配置activity的style为NoTittlebar)
1
2
3
4
5
6
7
8
|
Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); ViewGroup decorView = (ViewGroup) window.getDecorView(); view = new View( this ); view.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight( this ))); view.setBackgroundColor(getResources().getColor(R.color.color_top_bg)); decorView.addView(view); |
以上这篇Dialog全屏,去掉状态栏的方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/qq_31796651/article/details/83147992