【问题标题】:How to make a multi-color indeterminate linear progress indicator using material design in android?如何在android中使用材料设计制作多色不确定线性进度指示器?
【发布时间】:2021-07-18 07:36:13
【问题描述】:

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

在材料设计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" />

【问题讨论】:

    标签: android xml material-design android-progressbar material-components-android


    【解决方案1】:

    至少需要 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>
    

    【讨论】:

    • 是的,这行得通。我不知道如何在 XML 中引用数组。
    • @Gabriele Mariotti,感谢您的提示。我无法理解文档。
    猜你喜欢
    • 2023-03-10
    • 2023-01-26
    • 1970-01-01
    • 2022-06-10
    • 2015-01-05
    • 2020-02-09
    • 2019-02-28
    • 2015-08-15
    • 2017-05-25
    相关资源
    最近更新 更多