user6330086
user6330086

Reputation:

Changing the progress bar color

I am using a circular ProgressBar in my Activty. My Problem is that its color isnt changing properly where only BG color is Changing. So how can I change the color of ProgressBar without BG. I tried this thread- How to change default color of progress bar?

https://i.sstatic.net/DEpyM.jpg

Upvotes: 1

Views: 1610

Answers (2)

BamsBamx
BamsBamx

Reputation: 4266

Better way (using AppCompat libs):

final int color = Color.WHITE; // Or any other one
final ProgressBar progressBar= (ProgressBar) findViewById(R.id.progress_bar);
        DrawableCompat.setTint(progressBar.getIndeterminateDrawable(), color);

Upvotes: 1

Omar
Omar

Reputation: 458

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 :)

Upvotes: 3

Related Questions