title: Using DialogFragments. Are there bugs in the official example?
body: <p>I have just copied <a href="http://android-developers.blogspot.com/2012/05/using-dialogfragments.html" rel="nofollow noreferrer">the official example</a>, and my dialog is very narrow. Why?</p>
  
  <p><img src="https://i.stack.imgur.com/Ltk0B.png" alt="enter image description here"></p>
  
  <p>My code.</p>
  
  <p>The dialog.    </p>
  
  <pre><code>package com.redplanet;
  
  import android.os.Bundle;
  import android.support.v4.app.DialogFragment;
  import android.view.KeyEvent;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.WindowManager.LayoutParams;
  import android.view.inputmethod.EditorInfo;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.TextView.OnEditorActionListener;
  
  public class EditNameDialog extends DialogFragment implements OnEditorActionListener {
  
      public interface EditNameDialogListener {
          void onFinishEditDialog(String inputText);
      }
  
      private EditText mEditText;
  
      public EditNameDialog() {
          // Empty constructor required for DialogFragment
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_edit_name, container);
          mEditText = (EditText) view.findViewById(R.id.txt_your_name);
          getDialog().setTitle("Hello");
  
          // Show soft keyboard automatically
          mEditText.requestFocus();
          getDialog().getWindow().setSoftInputMode(
                  LayoutParams.SOFT_INPUT_STATE_VISIBLE);
          mEditText.setOnEditorActionListener(this);
  
          return view;
      }
  
      @Override
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
          if (EditorInfo.IME_ACTION_DONE == actionId) {
              // Return input text to activity
              EditNameDialogListener activity = (EditNameDialogListener) getActivity();
              activity.onFinishEditDialog(mEditText.getText().toString());
              this.dismiss();
              return true;
          }
          return false;
      }
  }
  </code></pre>
  
  <p>The activity.</p>
  
  <pre><code>package com.redplanet;
  
  
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.view.Menu;
  import android.widget.Toast;
  
  import com.redplanet.EditNameDialog.EditNameDialogListener;
  
  public class FragmentDialogDemo extends FragmentActivity implements EditNameDialogListener {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          showEditDialog();
      }
  
      private void showEditDialog() {
          FragmentManager fm = getSupportFragmentManager();
          EditNameDialog editNameDialog = new EditNameDialog();
          editNameDialog.show(fm, "fragment_edit_name");
      }
  
      @Override
      public void onFinishEditDialog(String inputText) {
          Toast.makeText(this, "Hi, " + inputText, Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          getMenuInflater().inflate(R.menu.activity_main, menu);
          return super.onCreateOptionsMenu(menu);
      }
  
  
  }
  </code></pre>
  
  <p>Activity layout file.</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:padding="@dimen/padding_medium"
          android:text="@string/hello_world"
          tools:context=".FragmentDialogDemo" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Dialog layout file.</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/edit_name"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/lbl_your_name"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Your name" /&gt;
  
      &lt;EditText
          android:id="@+id/txt_your_name"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:imeOptions="actionDone"
          android:inputType="text" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>