[英]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.