Reputation: 175
I want to have an onClick
that the chatlist-item
changes it's color when clicked/focused. I don't want to use any Java code if possible.
I tried this:
chatlist_layout.xml
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="false"
android:layout_alignParentRight="false"
android:background="@drawable/round_corners"
android:listSelector="@drawable/selector">
</ListView>
selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@color/ripple_material_light" /> <!-- focused -->
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/green_hsrt_1_default_CMYK_100_10_55_0" /> <!-- focused and pressed-->
<item android:state_pressed="true" android:drawable="@color/grey" /> <!-- pressed -->
<item android:drawable="@color/black" /> <!-- default -->
</selector>
what am I doing wrong?
Any kind of help will be greatly appreciated
Upvotes: 0
Views: 725
Reputation: 902
The problem may be in ListView background. So try to add android:drawSelectorOnTop="true"
Upvotes: 4