找了一会,好像只有这一种解决方案。
远离就是在菜单按钮上,添加一层布局,然后在这一层布局上试用动画
代码:
public void setRefreshActionButtonState(final boolean refreshing) { if (optionsMenu != null) { final MenuItem refreshItem = optionsMenu .findItem(R.id.action_refresh); if (refreshItem != null) { if (refreshing) { LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ImageView iv = (ImageView) inflater.inflate(R.layout.actionbar_flushing, null); Animation rotation = AnimationUtils.loadAnimation(this, R.anim.actionbar_rotate); if (iv != null && rotation != null) { iv.startAnimation(rotation); } MenuItemCompat.setActionView(refreshItem, iv); } else { MenuItemCompat.getActionView(refreshItem).clearAnimation(); MenuItemCompat.setActionView(refreshItem, null); } } } }
anim.xml
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="500" android:repeatCount="-1" android:interpolator="@android:anim/linear_interpolator" />
加入的一层布局:
layout.xml
<?xml version="1.0" encoding="utf-8"?> <ImageButton xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_action_refresh" style="@style/Widget.AppCompat.Light.ActionButton" />
由于兼容API7 ,所以用的 AppCompat
参考:http://stackoverflow.com/questions/9731602/animated-icon-for-actionitem
相关推荐
ActionBar溢出菜单颜色修改 可以参考blog http://blog.csdn.net/luohaowang320/article/details/38236929
ActionBar中的下拉菜单操作
仿微信下面的tabhost导航加右上角,actionbar实现,以及点击事件
ActionBar实现分页菜单(ActivityGroup+一些TextView布局.(在这里我们自定实现动态滚动效果))
侧拉菜单时actionbar图标做动画
ActionBar的各种设置和添加菜单项
ActionBar 动画效果,可以随意改变 ActionBar 的动画效果,因为你已经获取到了 ActionBar 的 View
作为“action项”没有出现在ActionBar上得菜单项会被置于“更多...”菜单项 中,在ActionBar上,“更多...”菜单项是以下拉形式实现的。 ② 为在多个fragments之间切换提供标签(tabs)功能; ③ 为导航提供下拉...
actionbar中增加setting菜单,用PopupWindow实现的,代码简单
popwindows实现actionbar上的小菜单的源码,具体用法详见博客。
2.当一个左侧drawer式的导航栏存在时,活动的activity会检测Actionbar上的按钮是否被按下,以此来显示或者关闭导航栏 3.ActionBarDrawerToggle有利于这种操作 4.抽屉内的item(每一项)应分为两类: 4.1视图切换 视图...
ActionBar的学习(自定义ActionBar的样式、在ActionBar上添加按钮、自动隐藏ActionBar)
这是我查看官方帮助文档完成的一个关于actionBar的例子,包括自定义菜单,和用actionBar实现菜单导航功能。
android仿微信6.0底部滑动菜单栏+导航栏,ViewPager+RadioGroup+ActionBar. 有博客描述
囊括了ActionBar大多的用法,包括搜索按钮常用配置,下拉菜单等。 从配置文件和代码两个方面来说明ActionBar的用法。
包括2个代码例子,一个是自定义 actionbar 适合用于3.0以下版本也需要使用actionbar。一个例子是 修改actionbar style样式,如果替换背景等。
actionbar实现Drawerlayout侧滑菜单在打开或关闭时侧滑按钮与返回按钮的切换
项目源码,里面包括了ActionBar的创建,ActionBar搜索按钮,显示不同的详情页面,给ActionBar添加Tab标签,抽屉布局及开关的开发
android actionbar的简单实例 带返回按钮
actionbar+fragment实现顶部导航菜单的功能