Mic*_*ele 8 android colors progress-bar
我需要以编程方式设置辅助进度条颜色.
我只看到了方法
ProgressBar.setProgressDrawable(drawable)
Run Code Online (Sandbox Code Playgroud)
用于设置主要颜色,但没有设置辅助颜色的方法.
我怎么能这样做?
ProgressBar.getProgressDrawable()返回 aLayerDrawable其中:
LayerDrawable progressDrawable = (LayerDrawable) getProgressDrawable();
Drawable backgroundColor = progressDrawable.getDrawable(0);
Drawable secondaryColor = progressDrawable.getDrawable(1);
Drawable primaryColor = progressDrawable.getDrawable(2);
Run Code Online (Sandbox Code Playgroud)
我尝试修改颜色(示例):
progressDrawable.setDrawableByLayerId(progressDrawable.getId(2), new ClipDrawable(...));
Run Code Online (Sandbox Code Playgroud)
但有时会死机,有时会死机。最后我因时间不够而放弃了寻找。对不起 :(
米歇尔
您指定使用的可绘制对象setProgressDrawable中有背景、主要和次要可绘制对象。以下是android 附带的可绘制对象的示例:ProgressBar
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient ... />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient .../>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient ... />
</shape>
</clip>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6425 次 |
| 最近记录: |