-1

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?

Avi Shukron
  • 6,088
  • 8
  • 50
  • 84
Emaborsa
  • 2,360
  • 4
  • 28
  • 50

2 Answers2

2

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.

Avi Shukron
  • 6,088
  • 8
  • 50
  • 84
-1

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.

Sachin Shelke
  • 449
  • 4
  • 12