0

有人告诉我创建自定义布局来更改对话框的默认大小。我似乎无法让它工作。

这是构建对话框的位置:

AlertDialog.Builder builder = new AlertDialog.Builder(context);
AlertDialog ad = builder.create();
LayoutInflater inflater = context.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_layout, null));
ad.setMessage("message");
ad.show();

这是布局 XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <View android:id="@+id/dialog_view"
        android:layout_width="400dp"
        android:layout_height="400dp"
        android:layout_weight="1" />

</FrameLayout>
4

1 回答 1

2

设置视图后从构建器创建警报对话框:

AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = context.getLayoutInflater();
builder.setView(inflater.inflate(R.layout.dialog_layout, null));
AlertDialog ad = builder.create();
ad.setMessage("message");
ad.show();
于 2013-01-31T21:46:05.283 回答