0

I am trying to set different color to the rounded progress bar. Below is my code..

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

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />

                <solid android:color="@color/purple" />
            </shape>
        </clip>

        <color android:color="@color/purple" />
    </item>
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />

                <solid android:color="@color/purple" />
            </shape>
        </clip>

        <color android:color="@color/purple" />
    </item>

</layer-list>

<ProgressBar
        android:id="@+id/progress_bar"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:progressDrawable="@drawable/progress_bar"
        android:visibility="visible" />

But this is not working. Still the progress bar is showing with gray color. Please help me, where i am going wrong?

Vid
  • 1,012
  • 1
  • 14
  • 29
  • Check this answer http://stackoverflow.com/questions/6421178/how-to-change-default-color-of-progress-bar . – Bae Feb 09 '15 at 09:58

2 Answers2

0

Make one xml folder in res directory and put the progress.xml file in it .

progress.xml

    <?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="#447a29" 
            android:endColor="#447a29"
            android:angle="0"
             />
    </shape>
</rotate> 

set startColor and endColor as per your choice .

now set that progress.xml in progressbar's backgound .

Like this

<ProgressBar
  android:id="@+id/ProgressBar01" 
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background ="@xml/progress">
Jitty Aandyan
  • 1,994
  • 1
  • 13
  • 12
0

Create an XML file named customprogressbar.xml in your res->drawable folder:

customprogressbarcolour.xml

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

    <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
    <shape>
        <gradient
                android:startColor="#000001"
                android:centerColor="#0b131e"
                android:centerY="1.0"
                android:endColor="#0d1522"
                android:angle="270"
        />
    </shape>
   </item>

  <!-- Define the progress properties like start color, end color etc -->
  <item android:id="@android:id/progress">
    <clip>
        <shape>
            <gradient
                android:startColor="#007A00"
                android:centerColor="#007A00"
                android:centerY="1.0"
                android:endColor="#06101d"
                android:angle="270"
            />
        </shape>
    </clip>
    </item>
</layer-list> 

Do the following in your XML:

<ProgressBar
    android:id="@+id/progress1"
    style="?android:attr/progressBarStyleHorizontal"
    android:progressDrawable="@drawable/custom_progressbar"         
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

At run time

Drawable draw=res.getDrawable(R.drawable.customprogressbarcolour);
    progressBar.setProgressDrawable(draw);
Sai Aditya
  • 2,353
  • 1
  • 14
  • 16