这就是我需要的:
显示您按下它的选择器。但是这个选择器也处理长按颜色转换。我看了很多,发现了这个。这基本上是我需要的,但这仅适用于图像,而不适用于颜色。这是我现在的代码:
default_selector.xml:
<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="@android:color/transparent" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@android:color/transparent" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/default_selector_transition" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/default_selector_transition" />
<item android:state_focused="true" android:drawable="@color/selection_grey" />
<item android:state_activated="true" android:drawable="@color/selection_grey"/>
<item android:drawable="@android:color/transparent" />
</selector>
default_selector_transition.xml:
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_pressed_default" />
<item android:drawable="@drawable/list_longpressed_default" />
</transition>
default_selector_transition.xml 中的可绘制对象现在有 9 个补丁。我想知道是否可以将其更改为颜色。
我尝试了什么:
- 只需在其中放置颜色而不是可绘制对象
- 在其中放置可绘制的颜色(
<drawable name="selection_grey_drawable">#BDBDBD</drawable>
)
希望大家给我一个解决方案!