Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...