我正在尝试将选择器应用于我的 ListView ,这是一个自定义 ListView ,我尝试了很多选项但没有任何效果。任何帮助将不胜感激。我附上我的代码。提前致谢
selector_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/faintblue" />
<item android:state_focused="true" android:drawable="@drawable/yellow" />
</selector>
layout_listview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" >
<ListView
android:id="@+id/lvChatList"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/rlHeader"
android:background="@drawable/selector_expandable_listview"
android:listSelector="@drawable/selector_expandable_listview" >
</ListView>
<TextView
android:id="@+id/tvNoChats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="No Chats"
android:visibility="gone" />
</RelativeLayout>
黄色背景效果有效但蓝色效果没有发生,请帮助 提前致谢
最佳答案
将此选择器设置为每一行的背景而不是 ListView 。
关于Android:ListView 选择器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20605413/