项目中用到拍照选择图片功能,选择图片弹窗用的是自定义AlertDialog。这个没什么难度。UI要求 对话框宽度铺满,底部在屏幕底部,无margin和padding。这个是实现起来挺简单的。想着布局里边不加margin和padding不久ok了
但是在自己手机小米5(android-7.0版本)安装看了下(顺带说一下小米5 在7.0版本下竟然不能连接androidstudio安装调试应用,这个有点扯),竟然有一块区域无法充满。如下图:
后来和同事讨论会不会是AlertDialog默认主题的原因。
WindowManager m = getWindow().getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
WindowManager.LayoutParams p = getWindow().getAttributes();
p.width = (int) (d.getWidth()); // 宽度设置为屏幕的k宽
// if(height > 0){
// p.height = (int) (d.getHeight() * height);
// }
p.horizontalMargin = 0.0f;
p.verticalMargin = 0.0f;
getWindow().setBackgroundDrawable(null);
BackgroundDrawable
制空发现可行。最终结果如图: