Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionbar progress indicator and refresh button

Tags:

Is it possible to show the progress indicator (the one that is show using requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) in place of a refresh button?

The idea is to work as Gmail client does: When not loading show refresh button and when loading show the indeterminate spinner in the place of refresh button

like image 963
lujop Avatar asked May 20 '12 19:05

lujop


1 Answers

Yes you can do it easily this way.

private MenuItem refresh; . . .  @Override public boolean onCreateOptionsMenu(Menu menu) {     getSupportMenuInflater().inflate(R.menu.options_menu, menu);      // refresh menu item     refresh = menu.findItem(R.id.refresh_option_item);      return super.onCreateOptionsMenu(menu); } 

You have to get your refresh menu item like above and then, you can enable spinning item like below:

refresh.setActionView(R.layout.actionbar_indeterminate_progress); 

and when you task is completed, you can disable spinning like below:

refresh.setActionView(null); 

And lastly, the actionbar_indeterminate_progress.xml can be like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="64dp"     android:layout_height="wrap_content"     android:gravity="center">     <ProgressBar android:layout_width="32dp"         android:layout_height="32dp"         android:layout_gravity="center"         style="?android:attr/indeterminateProgressStyle" /> </FrameLayout> 
like image 90
tasomaniac Avatar answered Sep 23 '22 03:09

tasomaniac