Davide Davide - 1 year ago 99
Android Question

How to change default ProgressBar circle color on Android

I am currently using an external library in my Android project imported via gradle.

This library show a notification bar with a ProgressBar circle.
This is the code I found in it's sources :


The style associated is this one :

<style name="SuperActivityToast_Progress_ProgressBar" parent="android:Widget.Holo.ProgressBar">
<item name="android:layout_width">32dp</item>
<item name="android:layout_marginLeft">8dp</item>

If I understand correclty, the color of the circle shown is derived from the default one ( green on my phone ).
I need to change it!

Now, I can't modify the source code, and the library itself doesn't offer me the possibility to set the style programmatically.

There is a way to change the default style at app level or better override this specific style?


Answer Source

After several attempts I found a solution :

ProgressBar progBar = (ProgressBar) context.getActivity().findViewById(R.id.progress_bar);
if (progBar != null) {
    progBar.getIndeterminateDrawable().setColorFilter(0xFFFFFFFF, android.graphics.PorterDuff.Mode.MULTIPLY);

Simply, i'll get a reference of the progress bar object created by the library and i change it's attributes. ( in my activity i must do that in a "OnStart" method otherwise it is null ) The most important part is the "setColorFilter" that do the magic.