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?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top