문제

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