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.
All of the other answers here makes sense, but it did not meet what Fabian needs. Here is a solution of mine. It may not be the perfect solution but it works for me. It shows a dialog which is on fullscreen but you can specify a padding on top, bottom, left or right.
As you can see I have there android:paddingTop= 20dp is basically what you need. The android:windowBackground = @color/Black0Percent is just a color code declared on my color.xml
That Color code just serves as a dummy to replace the default window background of the Dialog with a 0% transparency color.
Finally here is our dialog that set custom view which uses our dialog.xml:
Conclusion: I tried to override the dialog's theme in the styles.xml named CustomDialog. It overrides the Dialog window layout and gives me the chance to set a padding and change the opacity of the background. It may not be the perfect solution but I hope it helps you..:)
According to Android platform developer Dianne Hackborn in this discussion group post, Dialogs set their Window's top level layout width and height to
WRAP_CONTENT
. To make the Dialog bigger, you can set those parameters toMATCH_PARENT
.Demo code:
Note that the attributes are set after the Dialog is shown. The system is finicky about when they are set. (I guess that the layout engine must set them the first time the dialog is shown, or something.)
It would be better to do this by extending Theme.Dialog, then you wouldn't have to play a guessing game about when to call setAttributes. (Although it's a bit more work to have the dialog automatically adopt an appropriate light or dark theme, or the Honeycomb Holo theme. That can be done according to http://developer.android.com/guide/topics/ui/themes.html#SelectATheme )
You can use percentage for (JUST) windows dialog width.
Look into this example from Holo Theme:
All you need to do is extend this theme and change the values for "Major" and "Minor" to 90% instead 65%.
Regards.
Solution with actual 90% calculation:
where
getScreenWidth(Activity activity)
is defined the following (best put in a Utils class):My answer is based on the koma's but it doesn't require to override onStart but only onCreateView which is almost always overridden by default when you create new fragments.
I've tested it on Android 5.0.1.