0

我正在使用带有两个按钮的编辑文本字段动态构建警报对话框。对话框仅包裹非常小的宽度,我希望它拉伸以填充父宽度

public void showMessageDialog(String name){

    final AlertDialog.Builder alert = new AlertDialog.Builder(this);
    this.etMessage = new EditText(this);
    etMessage.setText("");
    alert.setMessage("Message " + name);
    alert.setView(etMessage);
    alert.setPositiveButton("Message", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            updateLocation();

        }
    });
    alert.setNeutralButton("Map", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            showMap();
        }
    });

    alert.show();
}
4

1 回答 1

0

我不知道如何从代码中做到这一点,但如果你从 XML 中扩展视图,你可以将layout_width="fill_parent"属性添加到顶级视图,它应该填满屏幕。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"

然后,您可以像这样膨胀视图:

View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_view, null);

并将其添加到 AlertDialog.Builder:

builder.setView(dialogLayout);
于 2011-01-06T04:22:39.897 回答