0
            final CharSequence[] options={"Indoor Pharmacy","Outdoor   Pharmacy","Laborataory"};

              AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
               builder3.create().getWindow().setLayout(1200, 1530);
                builder3.setTitle("Pick your choice").setItems(options, new DialogInterface.OnClickListener() {

                @Override

                public void onClick(DialogInterface dialog, int which) {

              // TODO Auto-generated method stub

              Toast.makeText(getApplicationContext(), "U clicked "+items[which], Toast.LENGTH_LONG).show();

              }

              });

                builder3.show()

我尝试使用上面的代码来显示带有 3 个选项的对话框。它工作正常,但我需要更改对话框的大小。你能帮我解决这个问题吗?

4

6 回答 6

3

试试这行代码:

builder3.create().getWindow().setLayout(300, 200);

希望能帮助到你!!

于 2013-08-02T04:39:35.320 回答
2

只需添加以下代码

Window window = Your_Dialog.getWindow();
window.setLayout(1300,900);
于 2013-08-02T04:49:41.110 回答
2

如果您希望它与您的屏幕尺寸相关,请使用这行代码

int width = getWindowManager().getDefaultDisplay().getWidth() - x;    
int height = getWindowManager().getDefaultDisplay().getHeight() - y; 
//where x and y are margin as required for ur dialog


AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
builder3.create().getWindow().setLayout(width, height);
builder3.setTitle("Pick your choice").setItems(options, new DialogInterface.OnClickListener() {
//rest of ur code
}
于 2013-08-02T05:18:40.923 回答
0

我认为您可以尝试创建一个对话框布局并在您的代码资源中调用它。

于 2013-08-02T04:36:31.107 回答
0

尝试

AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
Dialog d = builder3.setView(new View(this)).create();
d.getWindow().setLayout(600, 400);
d.show();
于 2013-08-02T04:39:36.523 回答
0

你还有标题栏吗?这可能会强制您的对话框变成特定大小。

在您的 DialogFragment 子类(或 Dialog 子类,没有getDialog())中尝试此代码:

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
于 2014-09-29T20:30:30.250 回答