How to set style to a progressBar programmatically on Android

假如想象 提交于 2020-02-19 09:51:09

问题


I have ProgressBar style in style.xml. When I create layout, put there ProgressBar and set style like:

style="@style/ProgressBarStyle"

set layout to dialog and all is fine.

Other way create view for dialog programmatically. So for ProgressBar I have next code:

new ProgressBar(context, null, R.style.ProgressBarStyle);

But in this way there is nothing instead ProgressBar.

P.S. I don't forget add ProgressBar to view which I set as dialog view.


回答1:


You can set your style from the constructor, for instance:

progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall);

Where the third attribute is the style.

In your case, I think the error is to choose a wrong one. Just this.



来源:https://stackoverflow.com/questions/26303558/how-to-set-style-to-a-progressbar-programmatically-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!