自定义AlertDialog在android-7.0上距离屏幕边界margin无法消除问题

来源:互联网 发布:node会取代php吗 编辑:程序博客网 时间:2024/06/05 06:47

项目中用到拍照选择图片功能,选择图片弹窗用的是自定义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);


再次尝试把dialog窗口
BackgroundDrawable
制空发现可行。最终结果如图:











1 0
原创粉丝点击