2

I have a problem in setting the height and width of an Alert Dialog, below is my Code that i have written in OnCreateDialog() method:

AlertDialog dialog = new AlertDialog.Builder(context ,AlertDialog.THEME_HOLO_LIGHT)
    .setTitle("Title")        
    .setAdapter(adapter, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            switch(which){

            case 0:
                //some Code
            break;
            case 1:                 
                //some Code
            break;
            }

        }
    })
    .create();


WindowManager.LayoutParams WMLP = dialog.getWindow().getAttributes();


WMLP.x = 80;   //x position
WMLP.y = -100;   //y position
WMLP.height = 100;
WMLP.width = 100;

dialog.getWindow().setAttributes(WMLP);
     //OR
dialog.getWindow().setLayout(100, 100);

Kindly tell me what is the problem here in the Code. Thanks

Muhammad Farhan Habib
  • 1,859
  • 20
  • 23
  • Possible duplicate [http://stackoverflow.com/questions/4406804/how-to-control-the-width-and-height-of-default-alert-dialog-in-android][1] [1]: http://stackoverflow.com/questions/4406804/how-to-control-the-width-and-height-of-default-alert-dialog-in-android – Simon Feb 09 '12 at 07:21

1 Answers1

8

You need to set the parameters for Height & Width after alertDialog.show();

So you need to call,

alertDialog.getWindow().setLayout(100, 100);

After calling

alertDialog.show();

For more check this answer.

Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242