Frage

I want to show/hide ProgressBar in ActionBar on all android devices. I am using android support library (android-support-v7-appcompat).

My activity extends ActionBarActivity and in onCreate it requests window feature supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); (before setting content).

On my button click I show/hide ProgressBar.

public void onClick(View v) {
    if(v.getId() == R.id.buttonProgress) {

        if(progress) {
            setProgressBarIndeterminateVisibility(false);
            progress = false;
        } else {
            setProgressBarIndeterminateVisibility(true);
            progress = true;
        }

    }
}

This code works fine on android API higher than 11. But I have proglem with API lower than 11. The ProgressBar is not showing up. There is no error in LogCat.

I have noticed that when I show ProgressBar in onCreate it works. I also can hide it from onCreate.

Do you have solution for this problem?

Thank you!

War es hilfreich?

Lösung

call

setSupportProgressBarIndeterminateVisibility(true)

if call it from fragment cast the activity for example:

ActionBarActivity ac =(ActionBarActivity) getActivity();
ac.setSupportProgressBarIndeterminateVisibility(true);

Andere Tipps

There is no action bar for apps lower than API 11.. If you use ProgressBar for Less than API 11 (Honeycomb) it does show up but it will tiny circle revolving on the top right of the title bar (thin bar on top of the app). Well, that depends on the theme.

If you want an actionbar you may want to look into an external library : ActionBarSherlock

The ActionBar APIs were first added in Android 3.0 (API level 11) but they are also available in the Support Library for compatibility with Android 2.1 (API level 7) and above.

And ActionBar is added in support liabrary to allow implementation of the action bar user interface design pattern back to Android 2.1 (API level 7) and higher. Use of this class requires that you implement your activity by extending the new ActionBarActivity class.

Have a look at the official document here

However you can achieve this by using ActionBarSherlock library.

Check out this

Site for ABS Here you can get the sample programs ABS Library

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top