Replacing a static refresh button with SupportProgressBarIndeterminateVisibility when clicked

1,237 views
Skip to first unread message

Davy De Waele

unread,
Jun 4, 2012, 7:31:51 AM6/4/12
to actionba...@googlegroups.com
Hi,

I have a refresh menu item icon on my actionbar (from the ICS icon set) that I want to replace with a small indeterminateDrawable from the holo theme when it's clicked.

I've styled the IndeterminateProgress like this to use the smaller indeterminateDrawable than the default one  :
<style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar.Small">
       <item name="android:indeterminateDrawable">@drawable/progress_small_holo</item>
</style>
When clicking on my refresh button, I call

setSupportProgressBarIndeterminateVisibility(true); 

This ensures that the small animating progress is shown in the actionbar alongside the refresh button. 

What I would like to do is to replace the refresh menu item icon with the indeterminateDrawable. What would be the best approach to do that ?

I'm currently just hiding the refresh menu item icon when it's clicked and calling 

setSupportProgressBarIndeterminateVisibility(true); 

Because the indeterminateDrawable is smaller than the refresh menu item icon, it's positioned too far to the right (next to another menu item), where I would want it to simply be positioned where the refresh menu item icon was. 

Is there an easy way to do that ?

luciofm

unread,
Jun 4, 2012, 9:06:23 AM6/4/12
to actionba...@googlegroups.com
I have used an ActionView.

when i click in the refresh button, I call refreshMenu.setActionView(R.layout.refresh_progress);

when the refresh is finished I do a refreshMenu.setActionView(null);


Lúcio Maciel
luc...@gmail.com

Alex Fu

unread,
Jun 4, 2012, 11:36:23 AM6/4/12
to actionba...@googlegroups.com
See this: http://alexfu.tumblr.com/post/19414506327/android-dev-animate-action-items

Although, it's not EXACTLY what you're asking, I think it's a bit better in terms of the user interface.

Davy De Waele

unread,
Jun 5, 2012, 4:33:15 AM6/5/12
to actionba...@googlegroups.com
How do you handle the animation in this case ? The android:indeterminateDrawable causes the drawable to rotate. Using an actionView it just displays the drawable without animation.


On Monday, June 4, 2012 3:06:23 PM UTC+2, luciofm wrote:
I have used an ActionView.

when i click in the refresh button, I call refreshMenu.setActionView(R.layout.refresh_progress);

when the refresh is finished I do a refreshMenu.setActionView(null);


Lúcio Maciel
luc...@gmail.com

Davy De Waele

unread,
Jun 5, 2012, 5:01:28 AM6/5/12
to actionba...@googlegroups.com
It does seem to require quite a bit of code :)

Also found another example in the google io app :

Reply all
Reply to author
Forward
0 new messages