Custom Progress bar color

147 views Asked by At

I am trying to change the default - green progress bar to a purple one. Some people here suggested creating a custom drawable (progress.xml) containing this code:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
    android:toDegrees="360">
<shape android:shape="ring" android:innerRadiusRatio="3"
       android:thicknessRatio="8" android:useLevel="false">

    <size android:width="76dip" android:height="76dip" />
    <gradient android:type="sweep" android:useLevel="false"
              android:startColor="#61408c"
              android:endColor="#e1d2f3"
              android:angle="0"
        />
</shape>

and than setting this to the background attribute of the progress bar like this:

<ProgressBar
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/progressBar"
    android:background="@drawable/progress"
    android:layout_centerInParent="true"/>

The problem is that I see both the purple and green progress bar indicators. The green is on top of the purple one. I don't know where the green progress bar comes from? The effect is this: enter image description here

1

There are 1 answers

0
Georgi Koemdzhiev On BEST ANSWER

I figured this out. I should set it in code, not as a background attribute! like this:

mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mProgressBar.setVisibility(View.INVISIBLE);
    mProgressBar.setIndeterminateDrawable(getDrawable(R.drawable.progress));