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

ame*_*ter 2 xml android android-progressbar material-design material-components-android

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

在此处输入图片说明

在材料的设计文档,它说我需要设置indeterminateAnimationTypecontiguous实现这一目标,并提供三种颜色。但是当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" />
Run Code Online (Sandbox Code Playgroud)

Gab*_*tti 6

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

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

        <com.google.android.material.progressindicator.LinearProgressIndicator
            android:id="@+id/progress"
            android:indeterminate="true"
            app:indeterminateAnimationType="contiguous"
            app:indicatorColor="@array/progress_colors"
            ../>
Run Code Online (Sandbox Code Playgroud)

array/progress_colors

<integer-array name="progress_colors">
    <item>@color/....</item>
    <item>@color/....</item>
    <item>@color/....</item>
</integer-array>
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明