如何以编程方式创建 ProgressBar? [英] How to create a ProgressBar programmatically?
问题描述
我的应用程序需要以编程方式创建一个小的 ProgressBar
.ProgressBar
没有设置样式的方法(我想要一个小的ProgressBar
).构造函数可以接受一个 AttributeSet
,但是,它是一个接口并要求我实现一组功能.有没有办法将ProgressBar
设置为小样式?(我不能使用 XML 来创建ProgressBar
.)
My application needs to create a small ProgressBar
programmatically.
ProgressBar
doesn't have a method to set the style (I want a small
ProgressBar
). The constructor can take an AttributeSet
, however, it is an
interface and requires me to implement a set of functions. Is there a way
to set the ProgressBar
to a small style? (I can't use XML to create
ProgressBar
.)
推荐答案
大多数情况下,如果您手动提供 AttributeSet
,则必须使用 Android 之一.幸运的是,他们公开了描述小进度条的属性集.使用此代码:
Most of the time if you provide an AttributeSet
manually you have to use one of Android's. Luckily, they've exposed the attribute set that describes a small progress bar. Use this code:
progressBar = new ProgressBar(activity, null, android.R.attr.progressBarStyleSmall);
这篇关于如何以编程方式创建 ProgressBar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!