自定义Dialog宽度无法全屏的解决方案

重写自定义Dialog的show()方法

@Override
public void show() {
    super.show();
    /**
     * 设置宽度全屏,要设置在show的后面
     */
    WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    layoutParams.gravity= Gravity.BOTTOM;
    layoutParams.width= WindowManager.LayoutParams.MATCH_PARENT;
    layoutParams.height= WindowManager.LayoutParams.WRAP_CONTENT;

    getWindow().getDecorView().setPadding(0, 0, 0, 0);

    getWindow().setAttributes(layoutParams);
}

并在super.show();后面加上如上代码

猜你喜欢

转载自blog.csdn.net/Stephen2Wong/article/details/64441852
今日推荐