Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Margins don't work for Dialogs, I imagine the top-level window view isn't a layout type that supports margins. I've seen posts saying margins will work when defined as the Dialog's style (rather than on the top-level view element), but this does not seem to work either.</p> <p>What you need to do to work around the issue is to use an <code>inset</code> drawable for your Dialog background, and adjust any padding to account for the background's extra inset. In the example below, I'll just set left &amp; right margins.</p> <p>Dialog background drawable:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- drawable is a reference to your 'real' dialog background --&gt; &lt;!-- insetRight and insetLeft add the margins --&gt; &lt;inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/dialog_background" android:insetRight="10dp" android:insetLeft="10dp"&gt; &lt;/inset&gt; </code></pre> <p>Dialog main view:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- paddingTop / paddingBottom padding for the dialog --&gt; &lt;!-- paddingLeft / paddingRight padding must add the additional inset space to be consistent --&gt; &lt;!-- background references the inset background drawable --&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft="15dp" android:paddingRight="15dp" android:background="@drawable/dialog_background_inset"&gt; &lt;!-- ...the rest of the layout... --&gt; </code></pre> <p>You may also need to set the background colour of the Dialog itself to transparent. Add a colour resource like so:</p> <pre><code>&lt;color name="transparent"&gt;#00000000&lt;/color&gt; </code></pre> <p>And set the window background colour of the dialog to this (note: you can't assign the colour directly, eclipse will complain)</p> <pre><code>&lt;style name="Dialog" parent="android:style/Theme.Dialog"&gt; &lt;item name="android:windowBackground"&gt;@color/transparent&lt;/item&gt; &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt; &lt;item name="android:windowIsFloating"&gt;true&lt;/item&gt; &lt;/style&gt; </code></pre> <p>This style should be passed to your Dialog's constructor as the <code>theme</code> argument, as in <code>new Dialog(context, R.style.Dialog);</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload