我想在AppCompat主题中按下列表视图项目时自定义长按颜色和动画。我使用自定义选择器。
listrongelector_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>
应该怎么做?
编辑。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" />
也许这对你有帮助。
我猜你需要记住:state聚焦标签
<item android:state_focused="true"/>
我认为你的问题是你已经创建了一个列表选择器,你正在使用它作为背景。列表选择器将优先于背景。您应该将其设置为ListView
上的listSelector
:
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@drawable/item_selector" />