Search code examples
androidandroid-listviewbackgroundbackground-colorlistviewitem

ListView item does not show Pressed background color when background draw-able set


I have a ListView. I want to set Border for the listView item so I use 'shape' xml.

shape_panel_drawable.xml file

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#ffffff" />

    <padding
        android:bottom="8dp"
        android:left="8dp"
        android:right="8dp"
        android:top="8dp" />

    <stroke
        android:width="1dp"
        android:color="#dadada" />

    <corners android:radius="8dp" />

</shape>

list_view_item.xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:background="@drawable/shape_panel_drawable" >
</RelativeLayout>

My issue is

If I use android:background="@drawable/shape_panel_drawable" - When I touch/press on a List item, I didn't see a Selected background color on the item. I see it if I remove 'background'.

Anyone has any ideas? Did I miss anything in order to be able to see selected background color if I use background drawable - 'shape_panel_drawable'?

Thank you!


Solution

  • Setting this on your ListView might help:

    android:drawSelectorOnTop="true"