0

I am trying the change the color of the indeterminate progress bar using styles. Added the following changes

in values/styles-v21

<style name="CustomHorizontalProgress" >
        <item name="android:indeterminateTint">#FF00FF</item>
        <item name="android:indeterminateTintMode">src_in</item>
</style>

and in values/styles

<style name="CustomHorizontalProgress" >
        <item name="colorAccent">#FF00FF</item>
</style>

and set these styles in progressbar as below

<ProgressBar
        android:id="@+id/progress"
        style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
        android:theme="@style/CustomHorizontalProgress"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:indeterminate="true"/>

For api>=21 everything this is working fine but colorAccent is not set as progress bar color in pre lollipop devices.

Note: I wanted to achieve this only using style.

devgun
  • 1,003
  • 13
  • 33

2 Answers2

0

Test it

<style name="CustomHorizontalProgress" parent="android:Widget.ProgressBar.Horizontal" >
    <item name="android:indeterminateTint">#FF00FF</item>
    <item name="android:indeterminateTintMode">src_in</item>

<style name="CustomHorizontalProgress" parent="android:Widget.ProgressBar.Horizontal">
    <item name="colorAccent">#FF00FF</item></style>

layout xml

   <ProgressBar
        android:id="@+id/progress"
        style="@style/CustomHorizontalProgress"
        android:theme="@style/CustomHorizontalProgress"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:indeterminate="true"/>

</style>
-2
progress.getProgressDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
Matthias
  • 4,481
  • 12
  • 45
  • 84
Ved
  • 502
  • 4
  • 9
  • take some time to read the question clearly(especially the note) rather than copy pasting answer just to increase your reputation. – devgun Mar 11 '19 at 12:15