Android - how to change the horizontal color of the progress bar without losing animation

Firstly, this is not a duplicate of the question "how to change the color of the progress bar", it solves my problem, but it creates another one.

So, I have a horizontal progress bar, I keep writing / updating the progress bar, i.e. set the progress to one, then two (up to 100) to simulate% completion, it works well if I do not change the color. However, as you know, on some phones the default resource color for the progress bar is green, some are orange, I want the color to be green on all devices, so in the progress bar attribute I set progressDrawable(recommended for most responses to Stackoverflow) to the following xmlfile

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
 <corners android:radius="5dip" />
 <gradient
  android:startColor="#4CC417"
  android:centerColor="#4CC417"
  android:centerY="0.75"
  android:endColor="#4CC417"
  android:angle="270"
/>
</shape>

If I do this, the progress bar now just displays all the progress (i.e. the final percentage, 100), you do not see the animation from 0 to any percentage.

  • Is there a way to change the default color of the progress bar and still have the default animation?

  • , , ? , - , ?

+5
1

"" "", , "secondaryProgress". , : https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/progress_horizontal.xml

drawable :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background">
        <shape>
            <corners android:radius="5dip" />
            <gradient
                    android:startColor="#ff9d9e9d"
                    android:centerColor="#ff5a5d5a"
                    android:centerY="0.75"
                    android:endColor="#ff747674"
                    android:angle="270"
            />
        </shape>
    </item> 

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#4CC417"
                        android:centerColor="#4CC417"
                        android:centerY="0.75"
                        android:endColor="#4CC417"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>

</layer-list>

, "clip" , "" . . http://developer.android.com/reference/android/graphics/drawable/ClipDrawable.html.

0

All Articles