Animationdrawable Is Not Playing In Actionbar?
Solution 1:
for me working call start() in next cycle
newHandler().post(newRunnable() {
@Overridepublicvoidrun() {
animationDrawable.start();
}
});
Solution 2:
I had the same problem. I was able to get around it by using an action bar provider as described here: http://developer.android.com/guide/topics/ui/actionbar.html#ActionProvider
Skip the ShareActionProvider and create a custom one. This lets you use a custom layout for your action bar item (an ImageView in this case) that you can manipulate as described in your link to the Drawable Animation guide.
Solution 3:
I'm telling this for someone that might end up here: in my app I just tried changing an icon of a button of the ActionBar with an AnimationDrawable with the same method and it works.
My AnimationDrawable ic_action_recording_active
:
<animation-listxmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="false" ><itemandroid:drawable="@drawable/ic_action_recording_active0"android:duration="200" /><itemandroid:drawable="@drawable/ic_action_recording_active1"android:duration="200" /><itemandroid:drawable="@drawable/ic_action_recording_active2"android:duration="200" /></animation-list>
I call this method after pressing on the icon (I handle them in the onOptionsItemSelected
):
publicvoidchangeMenuIcon(MenuItem item) {
if (isRecording) {
item.setIcon(R.drawable.ic_action_recording_active);
AnimationDrawableicon= (AnimationDrawable) item.getIcon();
icon.start();
} else {
item.setIcon(R.drawable.ic_action_recording);
}
}
EDIT: I just saw that using icon.start()
in the onCreateOptionsMenu
doensn't actually start the animation...
I ended up calling changeMenuIcon
in the onWindowFocusChanged
Post a Comment for "Animationdrawable Is Not Playing In Actionbar?"