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
相关推荐
Rain的Java大神之路1 小时前
Spring AI 2.0 GA 深度复盘:Java 后端做 AI 的分水岭,到底画在哪?如夏倾城3 小时前
进程状态模型详解:从三态、五态到 Linux 状态码映射小南家的青蛙4 小时前
JVM 参数调优实战指南SimonKing5 小时前
Typora 收费,开源产品Textus或可替代,还支持AI泡海椒5 小时前
Java 生成资金流向图 PDF:jquick-pdf 树图(JTreeChartData)节点尺寸与间距的追问记录Rain的Java大神之路5 小时前
别再死背八股了:读完 Spring 7.0.8 源码,我学会了"改"框架云草桑7 小时前
C#入坑JAVA 潜规则 API Get 多参数 Spring Boot与Spring Cloud 区别 入门系列4头发还在的女程序员15 小时前
Java充电桩平台源码解析:枪口状态、上报时间与页面刷新怎样协同Cosolar18 小时前
从 Java 21 升到 25、Spring Boot 3 升 4:一次可复现的迁移踩坑实录IT空门:门主20 小时前
LangChain4j 1.24.0 深度解读:新特性、版本对比与学习路线