如何操作栏中动画home键?栏中、操作、动画、home

2023-09-12 03:32:19 作者:絕版い少年ヾ

我使用ActionBarSherlock,我想进行动画处理的home键告诉用户点击它。我想用三个不同的图像来显示动画。

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?

推荐答案

获取操作栏在你的onCreate

ActionBar actionBar = getSupportActionBar();

创建并加载一个动画绘制这您在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);

发表的Runnable 启动动画时,主线程是明确的:

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!