gpt4 book ai didi

Android:如何实现长按列表项时的发光效果?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:06:29 28 4
gpt4 key购买 nike

使用默认选择器,长按列表项会导致其背景在两种颜色之间转换。

将选择器替换为下面的选择器会移除效果。根据this question ,我需要一个动画来重现它。我将如何在 xml 中执行此操作?

<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true">
<shape>
<solid
android:color="@color/state_pressed" />
</shape>
</item>
<item
android:state_focused="true">
<shape>
<solid
android:color="@color/state_focused" />
</shape>
</item>
<item>
<shape>
<solid
android:color="@color/state_idle_grey" />
</shape>
</item>
</selector>

最佳答案

这是来自 list_selector_background 的代码:

<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>

找到 on the web .

它使用这种过渡来实现长按点击:

<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>

找到 on the web too .

没有动画。记住让状态保持相同的顺序,或者至少在交换它们时考虑一下,顺序很重要。

就我个人而言,我喜欢事物以标准方式运行,所以我只使用标准列表选择器。

问候, 斯蒂芬

关于Android:如何实现长按列表项时的发光效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6513301/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com