AlertDialog Doesn't wrap Content
<p>My alertDialog doesn't wrap its content,I try many solution but didn't work I changed the style, used Dialog and ...
I want AlertDialog to wraps its content.</p>

<p>I'm getting this</p>

<p><a href="https://i.stack.imgur.com/USLXU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/USLXU.png" alt="enter image description here"></a></p>

<p>but I want this</p>

<p><a href="https://i.stack.imgur.com/VIZ7y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VIZ7y.png" alt="enter image description here"></a></p>

<p>custom layout:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/settings_ll"
              android:orientation="vertical"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="right"
              android:padding="5dp"
              android:layout_margin="10dp"
    &gt;
    &lt;TextView
        android:id="@+id/font_selection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="انتخاب قلم:"
        android:textColor="#000000"
        android:padding="10dp"
        android:background="#eeeeee"/&gt;
    &lt;Spinner
        android:id="@+id/font_selection_spinner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:spinnerMode="dropdown"
        /&gt;
    &lt;TextView
        android:id="@+id/size_selection"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="اندازه قلم"
        android:textColor="#000000"
        android:padding="10dp"
        android:background="#eeeeee"/&gt;
    &lt;LinearLayout
        android:id="@+id/select_font_size_ll"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"&gt;
        &lt;Button
            android:id="@+id/settings_small_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ریز"/&gt;
        &lt;Button
            android:id="@+id/settings_normal_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="معمولی"/&gt;
        &lt;Button
            android:id="@+id/settings_big_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="درشت"/&gt;
    &lt;/LinearLayout&gt;
    &lt;TextView
        android:id="@+id/sample_tv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:layout_gravity="center"
        android:gravity="center"
        android:text="این یک جمبه ی نمونه است"
        /&gt;
</code></pre>

<p><br> AlertDialog.java:</p>

<pre><code>public class SettingsDialog extends DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        // Get the layout inflater
        LayoutInflater inflater = getActivity().getLayoutInflater();

        // Inflate and set the layout for the dialog
        // Pass null as the parent view because its going in the dialog layout
        View view = inflater.inflate(R.layout.settings_layout, null);
        builder.setView(view);

        return builder.create();
    }
}
</code></pre>