Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indeterminate circle progress bar on android is white, despite colorAccent color

I'm unable to figure out how to change the color of the indeterminate circle progress bar on API-21. I've made sure that my colorAccent is set correctly. My understanding is that the system should take from colorAccent and tint the ProgressBar accordingly. Any idea what could be going wrong?

app/src/main/res/layout-v21/fragment_story_comments.xml

<ProgressBar         android:id="@+id/progress_bar"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerInParent="true"         android:visibility="visible"/> 

app/src/main/res/values/themes.xml

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">     <item name="colorPrimary">@color/colorPrimary</item>     <item name="colorPrimaryDark">@color/colorPrimaryDark</item>     <item name="colorAccent">@color/colorAccent</item>     <item name="android:windowNoTitle">true</item> </style> 

app/src/main/res/values/colors.xml

<color name="colorAccent">#ff5722</color> <color name="colorPrimary">#ff5722</color> <color name="colorPrimaryDark">#e64a19</color> 
like image 857
burntcookie90 Avatar asked Nov 16 '14 21:11

burntcookie90


People also ask

How do I stop indeterminate ProgressBar?

Avoid ProgressDialog If you need to indicate loading or indeterminate progress, you should follow the design guidelines for Progress & Activity and use a ProgressBar in your layout, instead of using ProgressDialog. Show activity on this post. Show activity on this post.

What is indeterminate ProgressBar android?

Indeterminate Progress Bar is a user interface that shows the progress of an operation on the screen until the task completes. There are two modes in which you can show the progress of an operation on the screen.


2 Answers

this works for lower versions of android, too:

if (progBar.getIndeterminateDrawable() != null) {         progBar.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.accent), android.graphics.PorterDuff.Mode.SRC_IN); } 
like image 33
bapho Avatar answered Sep 22 '22 08:09

bapho


Note: This only works from Android 5.0 (Lollipop) and up, as per the original request. For older Android versions you'll have to replace the ProgressBar's progressDrawable.

Expanding upon Liam's answer, I managed to get this working on XML using the indeterminateTint flag.

Apparently to get it to work, you need to set the indeterminate and indeterminateTintMode flags.

The mode is a bit of mystery for me. I tried all of them but only got the expected results with src_in and src_atop. I don't know what those modes actually do, so if anyone can expand on this I'd be grateful.

In any case this should work:

<ProgressBar     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:indeterminate="true"     android:indeterminateTint="#F00"     android:indeterminateTintMode="src_in" /> 
like image 69
Cachapa Avatar answered Sep 24 '22 08:09

Cachapa