Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 列表项长按转换_Android_Listview_Android Listview_Onlongclicklistener_Long Press - Fatal编程技术网

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>