5

I've been trying to change the color of the progressBar, and i've noticed it's using the accentColor (which is Blue in my case) and i've been trying to change it without luck.

Am I missing something?

This is in my styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="searchViewStyle">@style/AppTheme.SearchView</item>
    <item name="editTextColor">@android:color/white</item>
    <item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
    <item name="actionOverflowButtonStyle">@style/AppTheme.OverFlowItem</item>
    <item name="colorPrimary">@color/ColorPrimary</item>
    <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
    <item name="colorAccent">@color/ColorPrimaryDark</item>
</style>

This is my element in the layout.xml

<ProgressBar
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@style/Widget.AppCompat.ProgressBar"
    android:id="@+id/progressBar01"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:indeterminate="true"/>

My activity:

public class MainActivity extends android.support.v7.app.AppCompatActivity
octohedron
  • 3,868
  • 6
  • 42
  • 69

3 Answers3

3

If you want to change accent color for one specific view you need to create style own style and set it to the view using android:theme attribute.

UPDATED

<style name="CustomProgressBarTheme" parent="Widget.AppCompat.ProgressBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimaryCutom</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDarkCustom</item>
    <item name="colorAccent">@color/colorAccentCustom</item>
</style>


<ProgressBar
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:theme="@style/CustomProgressBarTheme"
android:id="@+id/progressBar01"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:indeterminate="true"/>
Volodymyr
  • 5,789
  • 4
  • 52
  • 78
0

Since you have colorAccent with that color, you will need to change the ProgressBar's color with this:

android:progressBackgroundTint="#a31212" // your color

As the doc says:

Tint to apply to the progress indicator background.

Finally:

    <ProgressBar
        android:id="@+id/progressBar01"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginStart="120dp"
        android:progressBackgroundTint="#a31212" />
ʍѳђઽ૯ท
  • 15,369
  • 7
  • 47
  • 103
  • Then what is it? -> `I've been trying to change the color of the progressBar` – ʍѳђઽ૯ท Feb 11 '16 at 15:46
  • @Gazta - Could you please be clear? You've been trying to change `AccentColor` or this `ProgressBar`? it's working with the above code, Interesting.. – ʍѳђઽ૯ท Feb 11 '16 at 15:49
  • How about the proof?: https://www.dropbox.com/s/0igkayxdf3c02e4/Capture.PNG?dl=0 :) – ʍѳђઽ૯ท Feb 11 '16 at 15:55
  • Like i guessed, it is not visible on Android Studio's Preview, but it is working on emulator.goodluck – ʍѳђઽ૯ท Feb 11 '16 at 16:02
  • What are the versions? because it should work only on +21 apis – ʍѳђઽ૯ท Feb 11 '16 at 16:05
  • So it should work on `5.0.1` and as you said, it's working on emulator.otherwise, you will need to change the color with a custom style like this: http://stackoverflow.com/questions/16893209/how-to-customize-a-progress-bar-in-android and still i'm trying to underestand what was the question about! – ʍѳђઽ૯ท Feb 11 '16 at 16:11
  • I know, but you said: `Can't change colorAccent from my application's theme` Actually the question has a problem and it's not clear what you've tried and what you exactly trying to achieve, that's why i said that.and about that Emulator and real device, perhaps it's a fault and maybe you want to contact with the developer or asking a question or opening an issue on code.google. – ʍѳђઽ૯ท Feb 11 '16 at 16:15
0

try this

 progressBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.ColorPrimaryDark), Mode.SRC_IN);
Sumit
  • 832
  • 10
  • 18