1

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.stack.imgur.com/DEpyM.jpg

Community
  • 1
  • 1
  • post some code. where's the xml for the progress bar? – Vucko May 14 '16 at 17:12
  • @Vucko I used code from this thread stackoverflow.com/questions/6421178/how-to-change-default-color-of-progress-bar –  May 14 '16 at 17:14

2 Answers2

3

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

Omar
  • 458
  • 2
  • 10
  • I need the color changing code which should be present in the @drawable/anyfile –  May 14 '16 at 17:18
  • by the way the drawable that represented here is a 9patch images consisting of one color as u wish, there is a 9patch creating tool with the sdk you can use it. – Omar May 14 '16 at 17:21
  • currently I use AIDE :P –  May 14 '16 at 17:22
  • also I am a noob... so its difficult for me to understand everything –  May 14 '16 at 17:23
  • so what exactly your question ? which part you didn't understood ? – Omar May 14 '16 at 17:27
  • check the screenshot... BG color I dont want, only PBar colour change –  May 14 '16 at 17:28
  • http://i.stack.imgur.com/dnE1I.jpg check the result, it has a dark green bg.. i dnt want that ,only pbar with blue color :) –  May 15 '16 at 04:46
  • I used indeterminateTint & indeterminateTintMode and now it Works! Still Thanks for ur Help :) –  May 15 '16 at 13:16
  • you can still change the colors, look at the gradient properties android:startColor="#007700" this is the color to start with and will end with android:endColor="#115511" so change the color to yor choise :) – Omar May 15 '16 at 14:43
1

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);
BamsBamx
  • 4,139
  • 4
  • 38
  • 63