This tutorial is form This blog, thanks.
private Menu optionsMenu;
// create options menu
@Override
public boolean onCreateOptionsMenu(Menu menu) {
this.mOptionsMenu = menu;
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_action_bar_main, menu);
return super.onCreateOptionsMenu(menu);
}
// change action button state (progress or refresh image)
public void setRefreshActionButtonState(final boolean refreshing)
{
if (mOptionsMenu != null)
{
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.airport_menuRefresh);
if (refreshItem != null)
{
if (refreshing) {
refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
} else {
refreshItem.setActionView(null);
}
}
}
}
//activity_action_bar_main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/airport_menuRefresh"
android:title=""
android:alphabeticShortcut="r"
android:orderInCategory="1"
android:showAsAction="always" />
</menu>
// actionbar_indeterminate_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="56dp"
android:minWidth="56dp">
<ProgressBar android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="center"/>
</FrameLayout>

0 意見:
張貼留言