Android 我的ListView背景选择器赢了';t突出显示所选行
我使用它作为向导,但当我单击一行时,它不会保持高亮显示。我的代码有什么问题 score_list.xmlAndroid 我的ListView背景选择器赢了';t突出显示所选行,android,listview,selector,Android,Listview,Selector,我使用它作为向导,但当我单击一行时,它不会保持高亮显示。我的代码有什么问题 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_par
<?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>
...
drawable/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>
<?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>
score\u row\u 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>
...
可绘制/行选择器.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>
<?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>
此代码现在可以正常工作。尝试对您的行选择器使用
state\u activated
。如果有人想知道,您也可以使用listview.clearChoices()清除所有选项;我必须使用此选项取消选择所有行。