如何以编程方式创建 ProgressBar?

编程入门 行业动态 更新时间:2024-10-09 12:29:12
本文介绍了如何以编程方式创建 ProgressBar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的应用程序需要以编程方式创建一个小的 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?

本文发布于:2023-11-28 11:14:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   ProgressBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!