是否可以在操作栏中设置(旋转)应用程序图标的动画。不是menuItems,而是屏幕左侧的应用程序图标。
我的应用程序有一个圆形徽标,只要应用程序正在运行,我就需要通过缓慢无限旋转来使其更具动态性。
提前致谢... 快乐编码
答案 0 :(得分:2)
操作栏接受Drawable
图标,因此您可以使用AnimationDrawable
并在资源中定义动画帧。查看Drawable Animation个android文档,了解如何创建和使用AnimationDrawable
。
另一种方法是将动画应用于主图标图像视图。
在res / anim / icon_rotate.xml中定义动画
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotY="50%"
android:pivotX="50%"
android:duration="1000"/>
从您的活动的onCreate
方法访问操作栏图标图片视图并设置动画。注意:您可能希望使用插值器和重复计数来播放此动画。
Animation a = AnimationUtils.loadAnimation(this, R.anim.icon_rotate);
findViewById(android.R.id.home).startAnimation(a);