如何操作栏中动画home键? [英] How to animate home button in action bar?

查看:166
本文介绍了如何操作栏中动画home键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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!

这篇关于如何操作栏中动画home键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆