Dialog全屏,去掉状态栏的方式
dialog即使设置全屏了,但还是有状态栏占用高度这;
直接将下面这行代码放到你的dialog中即可
@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宽高:
WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.width = width; attributes.height = height; getWindow().setAttributes(attributes);
添加两个基本的style
<!--普通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
退出全屏
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
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)
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全屏,去掉状态栏的方式就是小编分享给大家的全部内容了,希望能给大家一个参考
您可能感兴趣的文章:
- 设置Dialog全屏显示的两种方式
- android 全屏去掉状态栏和横竖屏设定
- 全屏Dialog在小米手机上状态栏遮挡导致无法全屏。
- android 全屏去掉ActionBar 和状态栏
- Android 以Dialog的方式显示Activity,并且处理背景四个角为圆角,去掉黑角
- window.open 全屏,js去掉工具栏,菜单栏,地址栏,状态栏..
- android去掉系统状态栏(StatusBar),让所有app程序均是全屏显示
- android中去掉标题栏和状态栏,实现全屏
- Android 去掉标题和状态栏 达到全屏显示
- Android去掉状态栏和标题栏的两种方式
- android中去掉标题栏和状态栏,实现全屏
- Android去掉状态栏和标题栏的两种方式
- android中去掉标题栏和状态栏,实现全屏
- 两种方式去掉Android状态栏和标题栏
- 几种方式设置全屏dialogfragment
- android AppCompat, splash启动白屏(黑屏)全屏,去掉状态栏,以及splash与虚拟按键遮挡
- android中去掉标题栏和状态栏,实现全屏
- Android Studio中隐藏状态栏(标题栏)实现全屏的方式
- android4.0.3 去掉系统状态栏(StatusBar),让所有app程序均是全屏显示
- Android_UI_全屏去掉标题栏和状态栏的两种方法