对话框没有填充屏幕

时间:2016-01-23 12:38:05

标签: android dialog

我已经为一些数据输入创建了一个对话框,在某些设备上它没有填满屏幕,它似乎是在包装内容,但在其他设备上它确实填满了屏幕(正如我所愿)。

Layout.xml

x

我已经在两台设备上测试过了;

HTC One M9(显示我想要的方式)

This is what I want

HTC One M9(显示我想要的方式)

This is not what I want

1 个答案:

答案 0 :(得分:1)

到目前为止,我记得,你必须像这样以编程方式操作:

   AlertDialog.Builder yourBuilder = new AlertDialog.Builder(this);
    Dialog yourDialog = new Dialog(this);
     //do some stuff with your dialog and builder
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(yourDialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    yourDialog = yourBuilder.create();
    yourDialog.show();
    yourDialog.getWindow().setAttributes(lp);