sr09 sr09 - 2 months ago 26
Android Question

ListView divider not showing in Android 5

I have a simple listview for which I have defined a custom drawable for the divider. I have defined the divider height to be 1dp. The listview is within a fragment.

<shape
android:shape="line" >
<stroke
android:color="@color/custom_color" />

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

</shape>


It works great for all Android versions except L.

Anything I'm missing?

Answer

You should use android:shape="rectangle" instead of android:shape="line" to make it work on every android version... (also change stroke to solid)

<shape
    android:shape="rectangle" >
    <solid android:color="@color/custom_color" />
    <gradient android:height="1dp" />
</shape>

Have fun!