Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put a progressBar on ActionBar

I am trying to put an indeterminate ProgressBar on the actionBar. I was using an actionView to put the progressBar like Google+ app for example.

<item     android:id="@+id/menu_progress"     android:actionLayout="@layout/action_progress"     android:menuCategory="container"     android:showAsAction="always"> </item> 

the problem is that the progress bar is considered as an item and therefore on a Nexus S portrait mode I have only one other item on the actionbar while on Google+ I can see two items plus the progressBar. How is it possible to put a progressbar using the android actionbar?

like image 803
Matroska Avatar asked Feb 06 '12 08:02

Matroska


People also ask

How do I add icons to my progress bar?

First of all you have to create a custom menu to use inside your activity. Secondly, you have to request the feature of progress bar inside your "onCreate". PS: All the above code is working using the ActionBar Compat Library.


1 Answers

NOTE: The functionality below is now deprecated in the Support Library.

You need to call

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) 

in your onCreate() before setting the activity's layout:

e.g.

@Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);     ... // set layout etc 

If you are using the support library replace requestWindowFeature with supportRequestWindowFeature

And then call

setProgressBarIndeterminateVisibility(true); 

on your Activity whenever you want to show the progress spinner.

like image 166
Kuffs Avatar answered Oct 02 '22 00:10

Kuffs