Setting Dialog Size Programmatically
21,150
Here is the code that ended up working:
dialog.getWindow().setLayout(275, 350);
![Ben Pearce](https://i.stack.imgur.com/djGhh.jpg?s=256&g=1)
Author by
Ben Pearce
I'm a freelance programmer located in San Francisco. I specialize in full lifecycle development of apps leveraging web services.
Updated on August 31, 2020Comments
-
Ben Pearce almost 4 years
In my program I create a dialog with the code below. Ideally I would like to scale the dialog by entering width and height parameter programmatically. Can anyone show me how to do this?
dialog = new Dialog(MainActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); popUpLayout = Globals.layoutInflater.inflate(R.layout.pop_up_layout, null); dialog.setContentView(popUpLayout); dialog.show();
-
Phillip Kigenyi over 3 yearsincase you want to match params, this might help. dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
-
Miguel Tomás almost 3 years@PhillipKigenyi your code did not work for me on SDK 30
-
Phillip Kigenyi almost 3 years@MiguelSilva Well I haven't investigated the changes in SDK 30, best guess is that there is an open api to do just the same implementation. Sorry for the inconvenience caused
-
Miguel Tomás almost 3 years@PhillipKigenyi no sorry necessary! ...i ended you defined the dimensions on the dialog's layout XML file