无法更改android对话框大小

时间:2013-08-02 04:31:38

标签: android dialog

            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个选项的对话框。它工作正常,但我需要更改对话框的大小。可以帮助我。

6 个答案:

答案 0 :(得分:3)

试试这行代码:

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

希望它能帮助!!

答案 1 :(得分:2)

只需添加以下代码

即可
Window window = Your_Dialog.getWindow();
window.setLayout(1300,900);

答案 2 :(得分: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
}

答案 3 :(得分:0)

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

答案 4 :(得分:0)

AlertDialog.Builder builder3=new AlertDialog.Builder(MainActivity.this);
Dialog d = builder3.setView(new View(this)).create();
d.getWindow().setLayout(600, 400);
d.show();

答案 5 :(得分:0)

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

在DialogFragment子类(或Dialog子类,不带getDialog())中尝试此代码:

    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);