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
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);
}
If you extends from a ActionBarActivity, try this:
public class MainActivity extends ActionBarActivity {
boolean showUp=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
setSupportProgressBarIndeterminateVisibility(Boolean.TRUE);
Button b = (Button) findViewById(R.id.myButton);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(showUp){
setSupportProgressBarIndeterminateVisibility(Boolean.FALSE);
}else {
setSupportProgressBarIndeterminateVisibility(Boolean.TRUE);
}
showUp=!showUp;
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With