Android警报对话框更改宽度

时间:2012-03-05 18:24:00

标签: android android-alertdialog

我有一个警告对话框(每行中的图像和文字),但它太宽了。如何更改对话框的宽度?

我的代码:

    ListAdapter adapter = new AnimalAdapter(this, _options );

    final AlertDialog.Builder ad = new AlertDialog.Builder(this);

    ad.setTitle("Options");
    ad.setSingleChoiceItems( adapter, -1, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String selectedVal = _options[which].getVal();
            options_selected_item = selectedVal;
            dialog.dismiss();
        }
    });
    ad.show();

我尝试在ad.getWindow().setLayout(600, 400);之前和之后添加ad.show();,但我得到了

The method getWindow() is undefined for the type AlertDialog.Builder.

2 个答案:

答案 0 :(得分:0)

对我建议的一些解决方案look here。我给出了一个代码示例,并尝试解释它是如何工作的。

答案 1 :(得分:0)

在显示之前尝试创建对话框:

Dialog dialog = ad.create();
dialog.show();
dialog.getWindow().setLayout(600, 400);
相关问题