Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of progress bar in android

i am trying to change the color of horizontal progress bar but it is not changing. i did some googling and gone through some example given in ur site. But i am not getting success to change the color accurately. i used progressBar.setProgressDrawable(Drawable d) but it sets the background color of the whole progress bar view instead of setting the background color of only the bar itself.

Please, any body help me.

thanks

like image 645
Sudipta Som Avatar asked Dec 29 '10 10:12

Sudipta Som


1 Answers

Hi I am using this code in my project. I hope it works for you.

// Create ProgressBar in your layout file.

    <ProgressBar
     android:id="@+id/yourid"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:progressDrawable="@drawable/slider"   
           />

// Create .xml file in your drawable folder with name slider.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@android:id/background"
        android:drawable="@drawable/grey_bar_music"/>
    <item android:id="@android:id/progress">
        <clip android:drawable="@drawable/blue_bar_music" />
    </item>
</layer-list>

//grey_bar_music ->Background image name for  your progressbar.
//blue_bar_music->Progress bar change color using this image when it start from 0.
like image 93
Rishabh Agrawal Avatar answered Sep 23 '22 15:09

Rishabh Agrawal