我想按下AppCompat主题中的listview项目时自定义长按颜色和动画。我正在使用自定义选择器。
这是list_selector_background_transition:
<?xml version="1.0" encoding="utf-8"?>
<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>
当按下它的工作时,但不是长按时。
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:endColor="@color/primary"
android:startColor="@color/accent"
android:angle="270" />
</shape>
</item>
</selector>
应该做什么?
EDIT。 item_selector.xml
<item android:state_window_focused="false" android:drawable="@android:color/transparent" />
<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" />
答案 0 :(得分:0)
答案 1 :(得分:0)
我认为您的问题是您创建了一个列表选择器,并将其用作背景。列表选择器将优先于背景。您应该将其设置为listSelector
上的ListView
:
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/item_selector" />