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.
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 to
AlertDialog.Builder adb = new AlertDialog.Builder(this); Dialog d = adb.setView(new View(this)).create(); // (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.) WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(d.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.MATCH_PARENT; lp.height = WindowManager.LayoutParams.MATCH_PARENT; d.show(); d.getWindow().setAttributes(lp);
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 )