I've seen some topics about handling colors of ProgressBars but none could answer my doubt.
I am using a horizontal ProgressBar
Indeterminate type.
I want it to have a transparent background while having a colored progressBar but cannot find a way to do it.
For a normal ProgressBar (not Indeterminate) I can get a LayerDrawable by calling progressBar.getProgressDrawable()
. Then using findDrawableByLayerId(android.R.id.background)
, I am able to tint just the background.
But using progressBar.getIndeterminateDrawable()
it returns me a GradientDrawable
, so I can't follow the same procedure.
Is it possible to get the colors from a GradientDrawable
for all APIs levels? Cause if it is, I could get the color of the background and change it.
Is there any solution for this?
Use color filter like this:
progressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.MULTIPLY);
progressBar.setProgressDrawable(R.drawable.progress_bar);
drawable/progress_bar.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="2dip" />
<gradient android:startColor="#43ffffff" android:centerColor="#43ffffff" android:centerY="0.75" android:endColor="#43ffffff" android:angle="270" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="2dip" />
<gradient android:startColor="#fff" android:endColor="#fff" android:angle="270" />
</shape>
</clip>
</item> </layer-list>
you can change color in this progress_bar.xml drawable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With