George
George

Reputation: 3817

Android::Create a progressBar from code-behind (java, not from xml)

I need to attach a progress bar to an AsyncTask. The AsyncTask works fine, but the progress bar is not.

The progress bar is actually a spinner! I imagine a progress bar being a horizontal thick line being filled from 0% to 100%. Instead I get a 'spinner'.

So, I tried mProgressBar.setIndeterminate(false); - it does not appear to have any effect. I guess the really important line is

style="?android:attr/progressBarStyleHorizontal" in the xml tag progressBar.

How can I do that from java code, and not xml ?

Upvotes: 2

Views: 2236

Answers (1)

Jethro
Jethro

Reputation: 988

When creating the progressbar the third parameter is where you specify the attribute. Here is an example of using the StyleHorizontal

ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);


Note: public ProgressBar (Context context, AttributeSet attrs, int defStyle)

Upvotes: 2

Related Questions