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

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Kind of makes sense, but somehow also doesn't. Anyway, I wished I read this answer 2 hours ago! Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.