Android Studio : ImageButton image/background flash

标签 android flash animation android-animation android-imagebutton

请告诉我,有没有一种简单的方法可以在 Android 中闪烁/切换 ImageButton 的背景或图像?

我基本上是试图让用户直观地知道何时对 ImageButton 执行单击操作。因此闪烁按钮会有帮助。

我尝试研究这个主题,但没有得出任何结果。唯一想到的是使用 Handler 实现一个 Timer 来在两个可绘制资源之间切换。但这似乎太过分了!

感谢你们对这位 Android 新手的耐心指导。

最佳答案

我建议您使用animation-list作为ImageButton的背景。

1) 创建flash_background.xml文件:

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">

    <item android:drawable="@drawable/first_background" android:duration="200" />
    <item android:drawable="@drawable/second_background" android:duration="200" />

</animation-list>

2)然后从代码

yourButton.setBackgroundResource(R.drawable.flash_background);
AnimationDrawable anim = (AnimationDrawable) yourButton.getBackground();
anim.start();

注意:

  • 您可以使用 android:duration 来加快/减慢动画速度。

关于Android Studio : ImageButton image/background flash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35468903/

相关文章:

java - RecyclerView ClickListener 无法识别触摸

java - Firebase Android 通过子键获取值

javascript - jQuery 的 stop() 似乎阻止了尚未排队的动画

Android ViewPager setCurrentItem 在 onResume 后不起作用

c# - 我可以使用什么技术为我的 C# 应用程序编写一个 View ?

css - 使用 CSS 设置 Flex MX ComboBox 背景颜色

flash - gotoAndPlay/gotoAndStop 不适用于数字帧标签

actionscript-3 - 确定是否正在播放影片剪辑

javascript - Angular ng-show ng-hide 动画

html - 不遵守 SVG 中的动画延迟