我使用this 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>
抽拉/ selector.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>
此代码现在可以正常使用。
答案 0 :(得分:8)
尝试使用state_activated
作为row_selector。