Android 列表项长按转换
这是我用于列表项选择器的内容:Android 列表项长按转换,android,listview,android-listview,onlongclicklistener,long-press,Android,Listview,Android Listview,Onlongclicklistener,Long Press,这是我用于列表项选择器的内容: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" <item android:drawable="@color/red" android:state_pressed="true"/> <!-- pressed --> <item android:draw
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
<item android:drawable="@color/red" android:state_pressed="true"/>
<!-- pressed -->
<item android:drawable="@color/green" android:state_pressed="false"/>
<!-- normal -->
</selector>
您可以按照建议使用列表选择器作为背景
并根据建议使用长按转换:-
可能它会帮助您..您可以使用一个来完成此任务。对于一个真实的示例,请查看ActionBarSherlock中列表选择器的一部分。您找到了吗?我也有同样的问题,代码看起来不错,但过渡没有发生,只有它的第一个颜色是长按使用。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@android:color/transparent" />
<!--
Even though these two point to the same resource, have two states so
the drawable will invalidate itself when coming out of pressed state.
-->
<item android:state_focused="true" android:state_enabled="false"
android:state_pressed="true" android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_enabled="false"
android:drawable="@drawable/list_selector_background_disabled" />
<item android:state_focused="true" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="false" android:state_pressed="true"
android:drawable="@drawable/list_selector_background_transition" />
<item android:state_focused="true"
android:drawable="@+drawable/list_selector_background_focus" />
</selector>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_selector_background_pressed" />
<item android:drawable="@drawable/list_selector_background_longpress" />
</transition>