繁体   English   中英

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

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

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

在此处输入图像描述

在材料设计文档中,它说我需要将indeterminateAnimationType设置为contiguous来实现这一点并提供三个 colors。 但是当indicatorColor属性只接受一种颜色时,如何提供三个colors呢?

当我运行此代码时,它会抛出一个异常,提示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" />

使用连续的 animation 至少需要 3 个指标 colors。

只需将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>

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM