How to animate home button in action bar?

允我心安 提交于 2019-12-25 11:35:41

问题


I'm using ActionBarSherlock and I would like to animate the home button to tell the user to click on it. I want to use three different images to show the animation.

How can I do this?


回答1:


Get the action bar in you onCreate:

ActionBar actionBar = getSupportActionBar();

Create and load an animation drawable which you defined in XML:

// homeDrawable is a field on your activity
homeDrawable = (AnimationDrawable) getResources().getDrawable(R.drawable.my_thing);

Set the drawable as the icon on the action bar:

actionBar.setIcon(homeDrawable);

Post a Runnable to start the animation when the main thread is clear:

getWindow().getDecorView().post(new Runnable() {
  @Override public void run() {
    homeDrawable.start();
  }
});

Don't forget to stop the animation at some point!



来源:https://stackoverflow.com/questions/16289686/how-to-animate-home-button-in-action-bar

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