簡體   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