Question

I'm trying to create a Custom Dialog, setting my layout in order to customize it, but keeping the standard width.

In THIS picture we see a basic Dialog(AlertDialog), which has a defined width. On phones it has the full width minus some pixel, on tablet it has a defined width taht can be seen HERE.

The problem by using a custom layout is that the width shrinks to a wrap content of the layout like in THIS picture.

How can i do in order to have a custom dialog, which uses my layout but behavies on size as a standard dialog?

Was it helpful?

Solution

It appears that after you set the content view for the dialog, you have to call:

dialog.getWindow().setLayout(
        ViewGroup.LayoutParams.MATCH_PARENT,
        ViewGroup.LayoutParams.WRAP_CONTENT);

And the dialog will have the same width as an AlertDialog.

OTHER TIPS

It seems like you used LinearLayout for dialog. Try to set your root layout as RelativeLayout. It will solve your problem.

Check this example in details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top