Android Indeterminate ProgressBar : Animating custom drawable

611 views Asked by At

I currently have an Indeterminate ProgressBar

 <ProgressBar
        android:id="@+id/progressBar2"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="5dp"
        android:background="#B8A1A1"
        android:indeterminate="true"
        android:indeterminateDuration="1000"/>

When I set a custom drawable using a gradient of colours, the progress bar no longer moves. It's a stationary bar.

val colors: IntArray = intArrayOf(Color.parseColor("#a8bded"),Color.parseColor("#0a3cad"),Color.parseColor("#a8bded"))
val gd = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,colors)
progressBar2.indeterminateDrawable = gd

How do I make the custom progressdrawable animate as usual?

1

There are 1 answers

0
Sruthi On BEST ANSWER

Setting useLevel=true fixed it.

val colors: IntArray = intArrayOf(Color.parseColor("#a8bded"),Color.parseColor("#0a3cad"),Color.parseColor("#a8bded"))
val gd = GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,colors)
gd.useLevel=true
progressBar.indeterminateDrawable = gd