Skip to content Skip to sidebar Skip to footer

How To Add Progressbar To Actionbarsherlock

Is it possible to add progressbar to ActionBarSherlock? I need to show and hide it in particular time. But it has to be located inside ActionBarSherlock. Code of my class. you can

Solution 1:

Yes. You can add a ProgressBar to an ActionBar using ABS.

This is an extract from the source provided below, if the solutions helps, +1 the original poster ;-)

In your onCreate() method, add this piece of code:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
setProgressBarIndeterminateVisibility(true);

And when you are done with the task that you need to display the ProgressBar for, hide the ProgressBar using this code:

setProgressBarIndeterminateVisibility(false);

Credit: https://stackoverflow.com/a/9157874/450534

Solution 2:

Yes, you can, ABS has such feature. Next piece of code is from Demos sample app of ABS:

publicclassProgressextendsSherlockActivity  {
    HandlermHandler=newHandler();
    RunnablemProgressRunner=newRunnable() {
        @Overridepublicvoidrun() {
            mProgress += 2;

            //Normalize our progress along the progress bar's scaleintprogress= (Window.PROGRESS_END - Window.PROGRESS_START) / 100 * mProgress;
            setSupportProgress(progress);

            if (mProgress < 100) {
                mHandler.postDelayed(mProgressRunner, 50);
            }
        }
    };

    privateintmProgress=100;

    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
        setTheme(SampleList.THEME); //Used for theme switching in samplessuper.onCreate(savedInstanceState);

        //This has to be called before setContentView and you must use the//class in com.actionbarsherlock.view and NOT android.view
        requestWindowFeature(Window.FEATURE_PROGRESS);

        setContentView(R.layout.progress);

        findViewById(R.id.go).setOnClickListener(newView.OnClickListener() {
            @OverridepublicvoidonClick(View arg0) {
                if (mProgress == 100) {
                    mProgress = 0;
                    mProgressRunner.run();
                }
            }
        });
    }
}

this sample you can find in samples\demos\ directory of ABS (Progress.java in eclipse workspace)

Solution 3:

For full compatibility you should use:

setSupportProgressBarIndeterminateVisibility(true);

Here is an example:

public class MyActivity extends SherlockFragmentActivity {
    //...@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);     
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);        
        setContentView(R.layout.my_layout);
        //...setSupportProgressBarIndeterminateVisibility(true);
    }
}

Post a Comment for "How To Add Progressbar To Actionbarsherlock"