gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:44:06 28 4
gpt4 key购买 nike

我想实现一个类似这样的进度条:
enter image description here
在 Material 设计中documentation它说我需要设置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" />

最佳答案

使用连续动画至少需要 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>
enter image description here

关于android - 如何在android中使用 Material 设计制作多色不确定线性进度指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67241052/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com