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
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>
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