How to Change Progress Bar'S Progress Color in Android

How to change progress bar's progress color in Android

I'm sorry that it's not the answer, but what's driving the requirement setting it from code ?
And .setProgressDrawable should work if it's defined correctly

<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/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80ffd300"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:angle="270"
/>
</shape>
</clip>
</item>

<item android:id="@android:id/progress">
<clip>
<shape>
<corners
android:radius="5dip" />
<gradient
android:startColor="@color/progress_start"
android:endColor="@color/progress_end"
android:angle="270"
/>
</shape>
</clip>
</item>

</layer-list>

How to change color in circular progress bar?

In the res/drawable folder, put this:

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="#00ffffff"
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:indeterminateDrawable="@drawable/progress"
/>

How to change ProgressBar's progress indicator color in Android

I copied this from one of my apps, so there's prob a few extra attributes, but should give you the idea. This is from the layout that has the progress bar:

<ProgressBar
android:id="@+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:indeterminate="false"
android:maxHeight="10dip"
android:minHeight="10dip"
android:progress="50"
android:progressDrawable="@drawable/greenprogress" />

Then create a new drawable with something similar to the following (In this case greenprogress.xml):

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:startColor="#ff9d9e9d" />
</shape>
</item>

<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#80ffb600"
android:centerY="0.75"
android:endColor="#a0ffcb00"
android:startColor="#80ffd300" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:endColor="#008000"
android:startColor="#33FF33" />
</shape>
</clip>
</item>

</layer-list>

You can change up the colors as needed, this will give you a green progress bar.

How to change default color of progress bar?

Please make one xml file name progress.xml and put it in res/xml folder and write the below code in that xml file.

 <?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>

after creating this xml file set your progressbars background as this xml ..

Like

<ProgressBar
android:id="@+id/ProgressBar01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background = "@xml/progress">

how to change ProgressBar color?

Try this code -

<?xml version="1.0" encoding="utf-8"?>
<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="#f58233" />
</shape>
</clip>

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

<solid android:color="#f58233" />
</shape>
</clip>

<color android:color="#f58233" />
</item>

</layer-list>

Progress Bar -

<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dp"
android:layout_height="3dip"
android:progressDrawable="@drawable/progress_bar" />

Change color codes according to your need

Change color of progress bar background in android

You will have to obtain the LayerDrawable used by the ProgressBar and then either

  • use findDrawableByLayerId(android.R.id.background) to get the Drawable for that layer and make modifications to it at runtime; or
  • create a new Drawable and call setDrawableByLayerId(android.R.id.background, newBackgroundDrawable)

If I recall correctly, <shape> tags result in a GradientDrawable being created at runtime by the system, and that conveniently has methods like setColor()

How to set the secondary color of determinate circular progress bar

You can create custom progressbar style.

custom_progress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:innerRadiusRatio="2.8"
android:shape="ring"
android:useLevel="false"
android:type="sweep"
android:thicknessRatio="18.0">
<solid android:color="@color/red"/>
</shape>
</item>
<item android:id="@android:id/progress">
<rotate
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="-90"
android:toDegrees="-90">
<shape
android:innerRadiusRatio="2.8"
android:shape="ring"
android:angle="0"
android:type="sweep"
android:thicknessRatio="18.0">
<solid android:color="@color/blue"/>

</shape>
</rotate>
</item>

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

</layer-list>

and in xml:

 <ProgressBar
android:layout_centerInParent="true"
android:id="@+id/winRateProgressBar"
android:layout_width="48dp"
android:layout_height="48dp"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="false"
android:max="100"
android:progress="20"
android:progressDrawable="@drawable/custom_progress"/>

Changing the progress bar color

You can do all in xml files
After some search I got the answer :

you progress bar code :

   <ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:indeterminateDrawable="@drawable/progress"
/>

and the progress drawable is consisting of a rotating ring has a gradiant color of your choise like this :

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

just like this , please rate this answer :)



Related Topics



Leave a reply



Submit