title: AlertDialog: How To Remove Black Borders Above and Below View
body: <p>This question has been asked before: <a href="https://stackoverflow.com/questions/10222241/alertdialog-custom-title-has-black-border">AlertDialog custom title has black border</a></p>
  
  <p>But was not answered satisfactorily - and is missing some information.</p>
  
  <hr>
  
  <p>I'm trying to create a custom dialog in Android without a title and without any buttons along the bottom.</p>
  
  <p>However, the resulting dialog has black "borders"/"spacing"/something along the top and bottom of the view.</p>
  
  <p>From <a href="http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog" rel="nofollow noreferrer">the Documentation</a>: </p>
  
  <blockquote>
    <p>A dialog made with the base Dialog class must have a title. If you
    don't call setTitle(), then the space used for the title remains
    empty, but still visible. If you don't want a title at all, then you
    should create your custom dialog using the AlertDialog class. However,
    because an AlertDialog is created easiest with the AlertDialog.Builder
    class, you do not have access to the setContentView(int) method used
    above. Instead, you must use setView(View). This method accepts a View
    object, so you need to inflate the layout's root View object from XML.</p>
  </blockquote>
  
  <p>So, that's what I did:</p>
  
  <p><strong>Welcome.java</strong></p>
  
  <pre><code>public class Welcome  extends Activity
  {
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.welcome);
  
          LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
          View layout = inflater.inflate(R.layout.welcomedialog, (ViewGroup)findViewById(R.id.layout_root));
  
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setView(layout);
          builder.create().show();
      }
  }
  </code></pre>
  
  <p><strong>welcomedialog.xml</strong></p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="@drawable/texturebg"
                android:id="@+id/layout_root"
                android:orientation="vertical"
                android:padding="40px"&gt;
      ...
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>NOTE:</strong> I've tried using <code>FrameLayout</code> as the root <code>ViewGroup</code> instead of <code>LinearLayout</code> as per a suggestion I found somewhere - but that didn't help. </p>
  
  <p><strong>Result</strong></p>
  
  <p><img src="https://i.stack.imgur.com/DSS08.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/EBol7.png" alt="enter image description here"></p>
  
  <hr>
  
  <h2>setBackgroundDrawable Suggestion</h2>
  
  <pre><code>public class Welcome  extends Activity
  {
      public void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.welcome);
  
          LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
          View layout = inflater.inflate(R.layout.welcomedialog, (ViewGroup)findViewById(R.id.layout_root));
  
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder.setView(layout);
          AlertDialog dialog = builder.create();
  
          dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
  
          dialog.show();
      }
  }
  </code></pre>
  
  <p>Didn't work for me.</p>