title: DialogFragment - Get width of dialog
body: <p>I'm trying to get the width of a <code>DialogFragment</code> on runtime, I've tried two methods which failed.</p>
  
  <p>First: inside <code>onCreateDialog</code> after the dialog has been created</p>
  
  <pre><code>public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      ...
      ...
      AlertDialog dialog =  builder.create();
      width = dialog.getWindow().getAttributes().width;
      return dialog;
  }   
  </code></pre>
  
  <p><code>width</code> was set to -1</p>
  
  <p>Second:</p>
  
  <pre><code>public void onStart() {
      width = getDialog().getWindow().getAttributes().width;
  }
  </code></pre>
  
  <p><code>width</code> was set to -2</p>