gpt4 book ai didi

android - 如何在进度条中将颜色设置为辅助可绘制对象

转载 作者:行者123 更新时间:2023-11-29 14:22:03 25 4
gpt4 key购买 nike

我有这个代码

 pb = (ProgressBar) findViewById(R.id.progressBar1);
final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };
ShapeDrawable pgDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null));
String MyColor = "#00FF00";
pgDrawable.getPaint().setColor(Color.parseColor(MyColor));
ClipDrawable progress = new ClipDrawable(pgDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);
pb.setProgressDrawable(progress);
pb.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));

此代码中的问题是,对于进度可绘制对象和次要进度可绘制对象,我具有相同的颜色。

如何设置二次进度颜色?

最佳答案

指定一个 progressDrawable,如下例所示:

这是一个布局:

<ProgressBar
android:id="@+id/gauge"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="4dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/section"
android:progress="50"
android:progressDrawable="@drawable/progressbar"/>

这会转到 drawable/progressbar.xml,您可以在此处为两个进度条指定背景和颜色。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
<shape>
<gradient
android:startColor="@color/basecolor"
android:endColor="@color/basecolor"
android:angle="270"
/>
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#808080"
android:endColor="#808080"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient
android:startColor="#ffcc33"
android:endColor="#ffcc33"
android:angle="270" />
</shape>
</clip>
</item>

关于android - 如何在进度条中将颜色设置为辅助可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12244994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com