Setting Dialog Size Programmatically

21,150

Here is the code that ended up working:

dialog.getWindow().setLayout(275, 350);
Share:
21,150
Ben Pearce
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, 2020

Comments

  • Ben Pearce
    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
    Phillip Kigenyi over 3 years
    incase you want to match params, this might help. dialog.getWindow().setLayout(WindowManager.LayoutParams.MATC‌​H_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
  • Miguel Tomás
    Miguel Tomás almost 3 years
    @PhillipKigenyi your code did not work for me on SDK 30
  • Phillip Kigenyi
    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
    Miguel Tomás almost 3 years
    @PhillipKigenyi no sorry necessary! ...i ended you defined the dimensions on the dialog's layout XML file