Android dialog width

I had the same problem.

I used following code to make dialog fill_parent and it worked fine.

public class SharePost extends Dialog
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.adaptor_contentsharepost);

        LayoutParams params = getWindow().getAttributes();
        params.height = LayoutParams.FILL_PARENT;
        getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);
    }
}

layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:id="@+id/dialogWidth"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    contents here

</LinearLayout>

I'm using:

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

Set a minimum width at the top most layout.

android:minWidth="300dp"

For example:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android" android:minWidth="300dp">

<!-- Put remaining contents here -->

</LinearLayout>

As Matthias points at out How can I get a Dialog style activity window to fill the screen? UMAR's solution works, but only if the window attributes are set AFTER setContentView() is called.


Try this. It works for me.

    dialog = new Dialog(Activity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.feedback_popup);
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.gravity = Gravity.CENTER;

    dialog.getWindow().setAttributes(lp);