android 解决AlertDialog 满屏有边距的问题
AlertDialog dlg = new AlertDialog.Builder(this).create();
dlg.show();
Window window = dlg.getWindow();
// 把 DecorView 的默认 padding 取消,同时 DecorView 的默认大小也会取消
window.getDecorView().setPadding(0, 0, 0, 0);
// 设置宽度
WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(layoutParams);
// ***重点: 加上下面那句代码,把边距的透明去掉
window.setBackgroundDrawable(new ColorDrawable(0));
// *** 主要就是在这里实现这种效果的.
// 设置窗口的内容页面,alertdialog.xml文件中定义view内容
window.setContentView(R.layout.alertdialog);
//设置弹出位置
window.setGravity(Gravity.BOTTOM);
//设置弹出动画
window.setWindowAnimations(R.style.main_menu_animStyle);
效果图:
参考相关博客: https://blog.csdn.net/w2064004678/article/details/109613772
https://www.cnblogs.com/guochangxin/p/11457537.html