public class FullScreenDialog extends Dialog {
public FullScreenDialog(Context context) {
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// 按空白处不能取消
setCanceledOnTouchOutside(false);
}
@Override
public void show() {
final Window window = getWindow();
if (window != null) {
// 获取焦点,防止导航栏闪烁
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
}
super.show();
hideNavigationBar(window);
if (window == null) {
return;
}
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 设置全屏属性
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
// 设置window背景透明
window.setBackgroundDrawableResource(android.R.color.transparent);
WindowManager.LayoutParams lp = window.getAttributes();
lp.alpha = 1.0f;
lp.dimAmount = 0.0f; //dimAmount在0.0f和1.0f之间,0.0f完全不暗,1.0f全暗
lp.format = PixelFormat.TRANSPARENT;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// 延伸显示区域到刘海
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
window.setAttributes(lp);
window.getDecorView().setPadding(0, 0, 0, 0);
}
/**
* 隐藏导航栏
*
* @param window window
*/
public void hideNavigationBar(final Window window) {
if (window == null) {
return;
}
final int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
// Set the content to appear under the system bars so that the
// content doesn't resize when the system bars hide and show.
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
// Hide the nav bar and status bar
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
}
}
全局居中dialog
sunbofiy232024-01-09 21:29
相关推荐
代码or搬砖19 小时前
TransactionManager 详解、常见问题、解决方法廋到被风吹走19 小时前
【Spring】Spring Context 详细介绍Kiyra19 小时前
LinkedHashMap 源码阅读sheji341619 小时前
【开题答辩全过程】以 山林湖泊生态文明建设管控系统为例,包含答辩的问题和答案幽络源小助理19 小时前
SpringBoot兼职发布平台源码 | JavaWeb项目免费下载 – 幽络源2501_9167665419 小时前
【Java】HashMap集合实现类不会聊天真君64719 小时前
设计模式、线程状态、上下文切换、线程安全(JAVA并发第二期)Swift社区19 小时前
死锁:线程卡死不是偶然,而是设计问题uup19 小时前
防止短信验证码接口被盗刷问题xxxmine20 小时前
ConcurrentHashMap 和 Hashtable 的区别详解