如何在android中使用material设计制作多色不确定线性进度指示器?

How to make a multi-color indeterminate linear progress indicator using material design in android?

我想实现一个类似这样的进度条:

在 material 设计 documentation 中说我需要将 indeterminateAnimationType 设置为 contiguous 以实现此目的并提供三种颜色。但是当 indicatorColor 属性只接受一种颜色时如何提供三种颜色?

当我 运行 这段代码抛出一个异常 Contiguous indeterminate animation must be used with 3 or more indicator colors:

<com.google.android.material.progressindicator.LinearProgressIndicator
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
app:indeterminateAnimationType="contiguous"
app:hideAnimationBehavior="outward"
app:showAnimationBehavior="inward"
app:trackThickness="5dp" />

至少需要 3 种指示器颜色才能使用连续动画。

只需将 indicatorColor 属性与数组一起使用:

        <com.google.android.material.progressindicator.LinearProgressIndicator
            android:id="@+id/progress"
            android:indeterminate="true"
            app:indeterminateAnimationType="contiguous"
            app:indicatorColor="@array/progress_colors"
            ../>

array/progress_colors:

<integer-array name="progress_colors">
    <item>@color/....</item>
    <item>@color/....</item>
    <item>@color/....</item>
</integer-array>