How to change default ProgressBar circle color on Android

Davide picture Davide · Aug 17, 2015 · Viewed 37.8k times · Source

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 :

<ProgressBar
            android:id="@+id/progress_bar"
            android:layout_height="match_parent"
            android:layout_marginBottom="4dp"
            android:layout_marginTop="4dp"
            style="@style/SuperActivityToast_Progress_ProgressBar"/>

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>
</style>

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?

Thanks Davide

Answer

bond picture bond · Sep 22, 2016

If you are using the AppCompat theme, it uses the accentColor to tint the circle.

If you want to tint it to a different color than the Theme, then you should consider using ThemeOverylay. E.g. If you want to make the circle tint red you could do the following:

in your styles.xml

<style name="RedAccent" parent="ThemeOverlay.AppCompat.Light">
    <item name="colorAccent">#F00</item>
</style>

in your ProgressBar, set the theme to be RedAccent.

<ProgressBar
            android:id="@+id/progress_bar"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:theme="@style/RedAccent"/>

And your circle will now be in red color!