安卓进度条 : how to set secondary color programmatically

标签 android colors progress-bar

我需要以编程方式设置辅助进度条颜色。

我只看到方法

ProgressBar.setProgressDrawable(drawable)

用于设置主色,但没有设置副色的方法。

我该怎么做?

最佳答案

ProgressBar.getProgressDrawable() 返回一个 LayerDrawable,其中:

LayerDrawable progressDrawable = (LayerDrawable) getProgressDrawable();
Drawable backgroundColor = progressDrawable.getDrawable(0);
Drawable secondaryColor = progressDrawable.getDrawable(1);
Drawable primaryColor = progressDrawable.getDrawable(2);

我尝试修改颜色(示例):

progressDrawable.setDrawableByLayerId(progressDrawable.getId(2), new ClipDrawable(...));

但有时画面卡住,有时死机。 最后我因为时间不够而放弃了寻找。 对不起:(

米歇尔

关于安卓进度条 : how to set secondary color programmatically,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235890/

相关文章:

android - 如何在 xamarin android 应用程序中创建应用程序设置,并显示在该应用程序的 Android 设置/应用程序/应用程序设置中?

java - 选中表格布局中的所有复选框

python-2.7 - 带有opencv库的python中的HSI颜色格式

delphi - 需要 Delphi 6 示例在 TIdSmtp 发送操作期间更新进度条,特别是对于大型附件

android - 如何将 Hashmap 数据设置为 android 中的 ListView ?

android - Android 应用程序安装在哪里?

javascript - 在javascript中将十六进制颜色转换为整数

html - 在鼠标悬停和鼠标单击时更改菜单颜色

java - 如何使用 Swing Timer 延迟进度条的加载

ios - 添加进度条到下载文件