0

Custom Color Listview Selected

Pada res, buat file color_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#04b3d3" />
    <item android:state_selected="true" android:color="#048563" />
    <item android:color="#04b3d3" />
</selector>

Pada textview property, tambahkan android:textColor=”@color/color_selector”.

<TextView
    android:id="@+id/tv_list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="@color/color_selector"/>

Pada program java, tambahkan view.setSelected(true);.

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        view.setSelected(true);
    }
});