How to change default ProgressBar circle color on Android

I am currently using an external library in an Android project imported through gradle.
This library shows a notification bar with a ProgressBar circle. This is the code I found in it:

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

Matching style:

<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 the match, the color of the circle shown is obtained from the default value (green on my phone). I need to change it!

Now I can’t change the source code, and the library itself does not offer me the opportunity to programmatically set the style.

Is there a way to change the default style at the application level or is it better to override this particular style?

Thanks Davide

+14
4

:

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

, , . ( OnStart, null) - "setColorFilter", .

+30

AppCompat, accentColor, .

, , ThemeOverylay. . red, :

styles.xml

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

ProgressBar, RedAccent.

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

!

+49

:

colorControlActivated AppTheme values /styles.xml:

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Main theme colors -->
    ....
    <!-- Color for circle in progress bar -->
    <item name="colorControlActivated">#DC0808</item>
</style>

<ProgressBar/> XML .

+5

ProgressBar, :

    <ProgressBar
    android:id="@+id/progressbar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:visibility="gone"
    android:indeterminateTint="@color/colorPrimary"  // add color here
    android:layout_centerVertical="true"/>
0

All Articles