问题描述
- Android 中 ListView selector 不能运行
-
我使用list selector,但是不能很好的运行。点击list item后可以获得效果,但是在点击item之前没有任何效果出现。下面是 selector 的代码:<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="false" android:state_pressed="false" android:drawable="@drawable/ic_launcher" /> <item android:state_pressed="true" android:drawable="@drawable/headerplain" /> <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/headerplain" /> <item android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/headerplain" /> </selector>
我已经把它应用到 listView
<ListView android:id="@+id/listView123" android:layout_width="match_parent" android:layout_height="wrap_content" android:listSelector="@drawable/list_selector" android:drawSelectorOnTop="true" android:focusable="true" > </ListView>
如何解决这个问题?谢谢!
解决方案
listView中设置Selector是没有错的, 是不是list_selector 不太对,
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/ic_launcher" />
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/headerplain" />
<item android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/headerplain" />
<item android:state_pressed="true"
android:drawable="@drawable/headerplain" /> <!--这句放到最后试试--> > </selector>
解决方案二:
android:background="@drawable/list_selector"用这种试试
时间: 2024-09-17 12:23:01