2

我使用这个 SO question作为指导,但是当我单击一行时,它不会保持突出显示。我的代码有什么问题?

score_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/score_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/keyboard"
        android:listSelector="@drawable/selector"
        android:choiceMode="singleChoice"
        android:divider="#CCCCCC"
        android:dividerHeight="1dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp" />
...
</RelativeLayout>

可绘制/选择器.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@color/highlight"/>
    <item android:state_pressed="true" android:drawable="@color/highlight"/>
</selector>

score_row_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scoreRowLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:background="@drawable/row_selector" >
...
</LinearLayout>

可绘制/row_selector.xml

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

此代码现在可以正常工作。

4

1 回答 1

8

尝试使用state_activated您的 row_selector。

于 2013-02-14T05:37:05.583 回答