Highlight ListView selected row

Other solution (mostly in XML)

1) set the choiceMode of the ListView to singleChoice

<ListView
    android:choiceMode="singleChoice"
.../>

2) Items of the list must be a Checkable View and use a Color State List as Background

eg: album_item.xml

<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
   android:background="@drawable/list_selector"
.../>

3) the background Color State (list_selector.xml) defines the highlight color

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/green" android:state_checked="true"/>
    <item android:drawable="@color/green" android:state_pressed="true"/>
</selector>

Leave a Comment