如何在Android上以编程方式为ProgressBar设置样式 [英] How to set style to a progressBar programmatically on Android
问题描述
我在style.xml中具有ProgressBar样式. 当我创建布局时,将ProgressBar放在其中并设置样式,如:
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.
以其他方式以编程方式创建对话框的视图. 因此,对于ProgressBar,我有下一个代码:
Other way create view for dialog programmatically. So for ProgressBar I have next code:
new ProgressBar(context, null, R.style.ProgressBarStyle);
但是以这种方式,没有什么可以代替ProgressBar.
But in this way there is nothing instead ProgressBar.
P.S.我不会忘记添加ProgressBar来查看设置为对话框视图的视图.
P.S. I don't forget add ProgressBar to view which I set as dialog view.
推荐答案
您可以从构造函数中设置样式,例如:
You can set your style from the constructor, for instance:
progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall);
第三个属性是样式.
在您的情况下,我认为错误是选择了错误的一个.就是这个.
In your case, I think the error is to choose a wrong one. Just this.
这篇关于如何在Android上以编程方式为ProgressBar设置样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!