0

2 つのボタンを持つ編集テキスト フィールドを使用して、アラート ダイアログを動的に作成しています。ダイアログ ボックスは、非常に小さい幅をラップするだけです。親の幅を埋めるために引き伸ばしたい

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 に答える