30

I am creating a ProgressBar in my app programmatically it is of SPIN style by default however I want it in HORIZONTAL style. I don't see any method/constant to achieve this.

And I don't want to use ProgressDialog as it'd be inconsistent with my App UI theme.

Any suggestions please?

4
  • you haven't read this developer.android.com/guide/topics/ui/dialogs.html
    – MKJParekh
    Jan 4, 2012 at 13:16
  • 1
    that explains ProgressDialog while I am appending ProgressBar directly in my view. It appears but not in Horizontal style. Please correct me if I missed anything in the link you suggested.
    – iuq
    Jan 4, 2012 at 13:24
  • I think there is something titled under "Showing a progress bar" can help you.
    – MKJParekh
    Jan 4, 2012 at 13:27
  • that article explains about ProgressDialog but not ProgressBar
    – waqaslam
    Jan 4, 2012 at 14:50

2 Answers 2

92

use this:

ProgressBar pb = new ProgressBar(context,
                                 null, 
                                 android.R.attr.progressBarStyleHorizontal);
2
  • 4
    this works when we initialize it. How can we do it afterwards? How can we change the style online?
    – tasomaniac
    Jan 7, 2013 at 11:58
  • 2
    you cannot change view's Style once it is initialized.
    – waqaslam
    Jan 7, 2013 at 12:22
3

If you are using a ProgressDialog then, here is a way to change the style of the progressBar in the ProgressDialog.

mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.