我在Android上使用圆形进度条,希望改变它的颜色。我正在使用
"?android:attr/progressBarStyleLargeInverse"
如何更改进度条的颜色?需要怎样自定义样式呢?此外,“style”在这里的定义是什么?
我在Android上使用圆形进度条,希望改变它的颜色。我正在使用
"?android:attr/progressBarStyleLargeInverse"
如何更改进度条的颜色?需要怎样自定义样式呢?此外,“style”在这里的定义是什么?
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/black</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="progressColor" parent="Widget.AppCompat.ProgressBar">
<item name="colorControlActivated">@color/black</item>
</style>
</resources>
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:theme="@style/progressColor"
app:layout_constraintBottom_toBottomOf="@+id/textView3"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="@+id/textView3" />
它从你的Res/Values/Colors.xml中获取颜色值 -> colorAccent,如果你更改了它,你的进度条颜色也会改变。
您可以使用以下代码更改进度条的颜色:
progressBar.getProgressDrawable().setColorFilter(
getResources().getColor(R.color.your_color), PorterDuff.Mode.SRC_IN);