我在单击时突出显示列表项颜色时遇到问题。这是我正在使用的代码
Listview 布局如下。我的自定义列表视图类正在扩展 ListView。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:focusableInTouchMode="true"
android:focusable="true"
android:background="@drawable/list_selector" // also tried this but it doesn't work
>
<TextView
android:id="@+id/textView_list_info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
>
</TextView>
<com.custom.listview.ViewEditListView
android:id="@+id/customListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/list_selector" //this line doesn't work.
/>
</LinearLayout>
list-selector.xml 如下
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/list_divider" />
<item android:state_pressed="true"
android:drawable="@drawable/list_divider_hover" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/list_divider_hover" />
</selector>
custom_row.xml 如下
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
**android:background="@drawable/list_selector"**> //this also didn't work.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/v_row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:textColor="#C11B17"
android:layout_alignParentLeft="true"
/>
------
我不知道为什么单击列表项时它没有突出显示。
谢谢CP