2

I want to change the background colour of a progress bar so that it is set to red if a condition is true and green if the condition is false. Current style is define in the code below:

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

<item android:id="@android:id/background">
    <shape android:shape="rectangle" >
        <solid android:color="@color/red" />
    </shape>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <solid android:color="@android:color/black" />
        </shape>
    </clip>
</item>

</layer-list>

I have tried setting the color programmatically but the whole bar becomes green and I can't see the progress (black) any more

distanceProgress.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_IN);

distanceProgress.getProgressDrawable().setColorFilter(getResources().getColor(R.color.green), PorterDuff.Mode.SRC_IN);

According to this Android change Horizonal Progress bar color post I can set a secondary progress but how can I switch between the two?

Ubaier Bhat
  • 854
  • 13
  • 33

0 Answers0