0

I have a CustomDialog (extending Dialog) which is currently set to wrap_content for both width and heigh. Problem is if I set the main text as something really short (say "hello") the dialog gets very small in width. I would like the dialog to always take all the space available, but still have the default margin from the edges of the screen.

I already tried various methods:

setting:

android:layout_width="match_parent"

on the dialog layout, doesn't have any effect.

doing:

int width = (int)(getContext().getResources().getDisplayMetrics().widthPixels*0.90);
getWindow().setLayout(width, LinearLayout.LayoutParams.WRAP_CONTENT);

causes the dialog to go at the start of the screen and doesn't change anything regarding the width

Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.horizontalMargin = 10;
        params.width = LinearLayout.LayoutParams.MATCH_PARENT;
        window.setAttributes(params);

makes the dialog take the whole screen but without any horizonthal margin

putting

<item name="windowMinWidthMajor">100%</item>
        <item name="windowMinWidthMinor">65%</item>

in the dialog style has no effect.

how do I accomplish that? Mind that the dialog is used all around the app, so putting any code outside of the dialog class itself is not an option.

jack_the_beast
  • 1,838
  • 4
  • 34
  • 67

0 Answers0