6

Android L is not able to draw dotted line as drawable background as below:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item> 
<shape  android:shape="line" >

    <stroke
        android:dashGap="1dp"
        android:dashWidth="1dp"
        android:color="#999999" />

    <size android:height="1dp" />

    </shape>
</item>
</selector>

I am also using layerType='software' in xml. Kindly help.

vinb
  • 113
  • 5

1 Answers1

14

1.The view must be at least 2dp in height (or wrap_content), in order for it to display since a stroke is designed to go around the view and it doesn't have room to do so in 1dp.

2.Add width to your xml:

<stroke
    android:width="1dp"
    android:dashGap="1dp"
    android:dashWidth="1dp"
    android:color="#999999" />

<size android:height="1dp" 
    android:width="1dp"/>

3.Use layerType='software'

Itai Hanski
  • 8,540
  • 5
  • 45
  • 65
  • 1
    android:width="1dp" in stroke is a must for android 5.0 and higher – AppiDevo May 13 '17 at 16:45
  • Hey Itai, the `size` declaration in your example is not correct. If the `stroke` in your `shape` has a `width` of `1dp` then its `size` must have a `height` of at least `2dp`. Likewise if the `stroke` in your `shape` has a `dashWidth` of `1dp` then its `size` must have a `width` of at least `3dp`. – Adil Hussain May 17 '19 at 10:39