问题
Is it possible to animate(rotate) the application icon in the actionbar. Not the menuItems but the application icon on the left side of the screen.
I have a circular logo for my app and I need to make it more dynamic by rotating it slowly and indefinitely as long as the app is running.
Thanks in Advance... Happy Coding
回答1:
Action bar accepts Drawable
for an icon, hence you can use AnimationDrawable
and define your animation frames in resources. Look through Drawable Animation android docs to understand how to create and use AnimationDrawable
.
Another way is to apply animation to an home icon image view.
Define animation in 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"/>
Access action bar icon image view from onCreate
method of your activity and set an animation. Note: you may want to play with interpolator and repeat count for this animation.
Animation a = AnimationUtils.loadAnimation(this, R.anim.icon_rotate);
findViewById(android.R.id.home).startAnimation(a);
来源:https://stackoverflow.com/questions/25377239/animating-the-application-icon-or-logo-in-the-actionbar