I can create and display a custom alert dialog just fine but even so I have android:layout_width/height="fill_parent"
in the dialog xml it is only as big as the contents.
What I want is dialog that fills the entire screen except maybe a padding of 20 pixel. Then the image that is part of the dialog would automatically stretch to the full dialog size with fill_parent.
Above many of the answers are good but none of the worked for me fully. So i combined the answer from @nmr and got this one.
Get the device width:
then use that for making dialog 90% of device,
Try wrapping your custom dialog layout into
RelativeLayout
instead ofLinearLayout
. That worked for me.By far the most simplest way I can think of -
If your dialog is made out of a vertical LinearLayout, just add a "height filling" dummy view, that will occupy the entire height of the screen.
For example -
Notice the
android:weightSum="1"
in the LinearLayout's attributes and theandroid:layout_weight="1"
in the dummy View's attributesWell, you have to set your dialog's height and width before to show this ( dialog.show() )
so, do something like this:
Here is my variant for custom dialog's width:
So depending on device orientation (
ThemeHelper.isPortrait(mContext)
) dialog's width will be either 95% (for portrait mode) or 65% (for landscape). It's a little more that the author asked but it could be useful to someone.You need to create a class that extends from Dialog and put this code into your
onCreate(Bundle savedInstanceState)
method.For dialog's height the code should be similar to this.