Android: Display dialogs in fullscreen

Ever wondered how to maximize a dialog to the screen's full size? The first thing probably everyone would naturally do is to set
android:layout_width="fill_parent" android:layout_height="fill_parent"
in your mydialog.xml layout file. However, that doesn't seem to have any effect at all.

The solution that works is not much more complicated than that, but unfortunately not that easy to think of in the first place. What you have to do is, when you setup your Dialog in code, you have to set (again) your layout (as you do in the .xml file) after you set your content view.
I don't know why it works when set in code and not when set in the .xml file, but for now I just accept that it does. If you know the answer to this please let me know in the comments.

2 comments:

  1. Thanks Stefan, I've been looking for the solution to this for days (not continuously :-) ).

    ReplyDelete
  2. Thanks to found out this weird behaviour.

    When I tried to implement that in onCreateDialog() mechanisms, it didn't work at all .... the same behaviour than XML layout file. But it worked fin in onPrepareDialog() callback. Example :

    protected void onPrepareDialog(int id, Dialog dialog)
    {
    ......
    dialog.getWindow().setLayout(350, LayoutParams.WRAP_CONTENT);
    ......
    }

    Hope it will help.

    Once again, thanks for this workaround.

    Arnaud

    ReplyDelete