Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

android - Show progress spinner (refresh) on ActionBar?

I'm using the ActionBar. I'd like to have a refresh progress spinner on the titlebar, if I set it to spinning - otherwise hide it. Is that possible?:

// My menu has a refresh item, but it shouldn't be visible on the
// actionbar unless it's spinning.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:id="@+id/menu_refresh"
    android:title="@string/refresh"
    android:icon="@drawable/ic_action_refresh" />
</menu>

...

// When I need to show some work being done on my activity,
// can I somehow now make the spinner associated with the
// refresh item become visible on the action bar?
getActionBarHelper().setRefreshActionItemState(true);

I don't want it on the ActionBar unless it's "in progress" / spinning.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Apologies for no code tags, posting from phone...

This is from ActionbarSherlock (Google that if you've not come across it, allows actionbar support in pre honeycomb)

In onCreate of main activity

// This has to be called before setContentView and you must use the 
// class in android.support.v4.view and NOT android.view

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

To show/hide progress in action bar. Notice with actionbarsherlock you must use boolean.TRUE/FALSE, not just true/false.........

if (getSupportLoaderManager().hasRunningLoaders()) {
   setProgressBarIndeterminateVisibility(Boolean.TRUE); 
} else {
   setProgressBarIndeterminateVisibility(Boolean.FALSE); 
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...