我正在尝试为ListView应用选择器,以便那些没有触摸屏的人更容易地浏览我的应用程序。问题是,通过将选择器应用于ListView,它似乎只将背景颜色应用于整个列表,而不是其中的项目。
有什么想法吗?这里是一些代码:
有什么想法吗?这里是一些代码:
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/listselector"
/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="There are no Clients yet."
/>
在drawable文件夹中的listselector.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector
android:id="@+id/myselector"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item
android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/darkblue" />
<item
android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/green" />
<!-- Focused states -->
<item
android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@color/green" />
<item
android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@color/green" />
<!-- Pressed -->
<item
android:state_pressed="true"
android:drawable="@color/green" />
</selector>