如何给Actionbar添加动画(支持2.3)
来源:互联网 发布:看门狗2低配优化补丁 编辑:程序博客网 时间:2024/06/04 20:12
注:需要导入v4包
private MenuItem refreshItem;
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_refresh:
showRefreshAnimation(item);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void showRefreshAnimation(MenuItem item) {
refreshItem = item;
//这里使用一个ImageView设置成MenuItem的ActionView,这样我们就可以使用这个ImageView显示旋转动画了
ImageView refreshActionView = (ImageView) LayoutInflater.from(getActivity()).
inflate(R.layout.actionbar_refresh_view, null);
refreshActionView.setImageResource(R.drawable.refreshnormal);
// refreshItem.setActionView(refreshActionView); //该方法必须11以上
MenuItemCompat.setActionView(item, refreshActionView);//替换为使用v4兼容包
//显示刷新动画
Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotateanim);
animation.setRepeatMode(Animation.RESTART);
animation.setRepeatCount(Animation.INFINITE);
refreshActionView.startAnimation(animation);
}
public void hideRefreshAnimation() {
if (refreshItem != null) {
/// View view = refreshItem.getActionView();
View view = MenuItemCompat.getActionView(refreshItem);
if (view != null) {
view.clearAnimation();
refreshItem.setActionView(null);
}
}
}
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:funshion="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_deleted"
android:icon="@drawable/common_delete_btn_selector"
android:title="@string/delete"
funshion:showAsAction="ifRoom"/>
<item
android:id="@+id/action_refresh"
android:icon="@drawable/refreshnormal"
android:title="@string/refresh"
funshion:showAsAction="ifRoom"/>
</menu>
actionbar_refresh_view.xml
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
style="@android:style/Widget.ActionButton"
android:layout_height="wrap_content"
android:scaleType="centerInside" />
- 如何给Actionbar添加动画(支持2.3)
- 给ActionBar中的按钮添加旋转动画(刷新动画)
- (转)给ActionBar中的按钮添加旋转动画(刷新动画)
- 添加ActionBar的支持
- 如何添加ActionBar
- 给TableViewCell添加动画
- 给cell添加动画
- SpriteBuilder中如何给精灵添加帧动画
- 如何给一个应用添加一个StartView动画呢?
- 如何给ViewPager的条目添加渐变动画
- Android ActionBar中的按钮添加旋转动画
- Android ActionBar中添加旋转动画
- 如何给Win32 DLL添加MFC支持?(Dllmain重定义的问题)
- vs2013中如何给一个项目添加MFC支持
- Carthage 使用 / 如何给自己的项目添加 Carthage 支持
- 给控件添加动画效果
- 给TableView Cell 添加动画
- 给ViewPager添加切换动画
- UINavigationController使用的一些技巧
- Android入门:Activity四种启动模式
- A010:tail 命令详解-日志文件
- 三角网法计算土方量
- makefile 教程
- 如何给Actionbar添加动画(支持2.3)
- 关于ARM的22个常用概念
- [后缀数组+思路] hdu 4416 Good Article Good sentence
- POJ 3525 二分答案,推进多边形和半平面交
- JS正则表达式RegExp(字符串对象常用方法(二))
- arcgis 瓦片图加载规则
- HDU 3061 Battle(最小割----最大权闭合图)
- libghttp 封装使用实例
- 编程之美------之数字之魅