I would like to add an indeterminate progress bar to the Honeycomb ActionBar, so that any time the user presses "Refresh", the refresh icon temporarily turns into an indeterminate progress bar, until the task completes. The Email app does this already, but I can't figure out how.
Any advice?
You can easily do it by:
To clarify Jon O's answer, the key is to set and unset an action view on the refresh action. This works in both ActionBarSherlock and native 4.x action bar. The following snippet will put the progress indeterminate view on top of the refresh icon, assuming the refresh menu item has ID 'refresh_option' and the replacement layout (which has a ProgressBar) is in layout 'progress_wheel':
Unset the progress view, and the refresh icon will return to visibility:
See a more detailed example on github.
I'm using the code provided at the original issue here: https://github.com/JakeWharton/ActionBarSherlock/issues/425
Except for
android:layout_width
andandroid:layout_height
(in the actionbar_indeterminate_progress.xml) I use32dp
; as this was the way it was done in ActionBarCompat: http://developer.android.com/resources/samples/ActionBarCompat/res/layout-v11/actionbar_indeterminate_progress.htmlHard to tell exactly how the Email app does it, but you may want to stay simple and just call setIcon with the id of a
StateDrawable
XML file, and then just change the state using a Timer.It turns out that Google has posted an example of doing exactly this as a part of their broader ActionBarCompat compatibility project. Have a look.
To simplify larham1's answer: you don't even need to inflate new action view itself because
MenuItem
has the method which accepts id of action layout, so you can simply write: