0

我在单击时突出显示列表项颜色时遇到问题。这是我正在使用的代码

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

4

1 回答 1

1

如果您使用自定义行来设置列表视图..将此选择器放入您的 row.xml 中,如 android:background="@drawable/this_selector_name"

this_selector_name.xml

<item android:state_selected="true"><shape>
        <gradient android:angle="270" android:centerColor="#4EA0F2" android:endColor="#224466" android:startColor="#BED5ED" />
    </shape></item>
<item android:state_pressed="true"><shape>
        <gradient android:angle="270" android:centerColor="#4EA0F2" android:endColor="#4EA0F2" android:startColor="#4EA0F2" />
    </shape></item>
<item><shape>
        <solid android:color="@color/yellow" />
    </shape></item>

于 2013-04-11T05:14:34.637 回答