Animating the Application Icon or Logo in the actionbar

做~自己de王妃 提交于 2019-12-24 08:20:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!