ActionBar是Android提供的系统控件,这里能够为用户提供十分便捷的导航等操作。但是,有时候会觉得,在ActionBar上,为这个按钮添加一些动画效果,能够进一步提升用户感受。这篇文章,就简单介绍,ActionBar上按钮的动画是如何实现的。
首先,我们需要写一个菜单,命名为main_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/refresh"
android:icon="@drawable/ic_refresh"
android:showAsAction="ifRoom|withText"
android:title="刷新">
</item>
</menu>
在Activity中,生成菜单
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.main_browser, menu);
refresh = menu.findItem(R.id.refresh);
return true;
}
其中,refresh是一个MenuItem,是刚刚在main_menu.xml中定义的一个菜单选项