1

I need to re-size my alert dialog box to a custom height and width. How would I be able to do this by code so I could set it up with my screen height and width variables?

user
  • 86,916
  • 18
  • 197
  • 190
wesdfgfgd
  • 683
  • 1
  • 13
  • 26

3 Answers3

2
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

taken from this post here: How to resize AlertDialog on the Keyboard display

Also you might want to take a look at this one too Resize AlertDialog to fit image exactly

Alternatively if you cannot find a solution it might be best to think about making it an activity rather than an alert dialog

Community
  • 1
  • 1
Brent Hacker
  • 394
  • 2
  • 8
  • 26
1

look, i used to have that problem, i could resolve this problem with this code:

Well, you have to set your dialog's height and width before to show this ( dialog.show() ) so, do something like this:

dialog.getWindow().setLayout(width, height);

//then
dialog.show()
shontauro
  • 1,812
  • 1
  • 25
  • 26
  • It would work with just regular dialogs however it doesn't work well with my method of building alert dialog. I am using AlertDialog.Builder builder as a builder tool to create my LayoutInflater. – wesdfgfgd Feb 28 '12 at 16:05
  • mm so try to resize the content view of your alert dialog, for do this just keep an instance variable of your arert dialog contentview and change if width and height – shontauro Feb 29 '12 at 01:40
  • I fixed mine before with just a simple change from linear layout to relative layout. – wesdfgfgd Feb 29 '12 at 13:47
  • ok, relative layout is the most flexible of all layouts, i almost always use relativelayout to build my layouts – shontauro Mar 03 '12 at 16:58
0

On your .xml file use relative layout to auto maximizes to how big the dialog could be. Also you can manipulate data inside the relative layout much more easier if you customize your screen accordingly on the graphic end. I hope this helps someone who may encounter my problem.

wesdfgfgd
  • 683
  • 1
  • 13
  • 26