开发者

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

开发者 https://www.devze.com 2023-01-30 17:44 出处:网络
I need to attach a progress bar to an AsyncTask. The AsyncTask works fine, but the progress bar is not.

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 mProgr开发者_运维知识库essBar.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 ?


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消