开发者

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 wh开发者_如何学运维ole progress bar view instead of setting the background color of only the bar itself.

Please, any body help me.

thanks


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.


You Can create custom_progress.xml file in drawable folder -
<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="2"
        android:thicknessRatio="6" android:useLevel="false">

        <size android:width="76dip" android:height="76dip" />
        <gradient android:type="sweep" android:useLevel="false"
            android:startColor="#c76a37" 
            android:endColor="#A4B4B9"
             />
    </shape>
</rotate> 

//And add below code to your layout file to create progress bar
 <ProgressBar
        android:id="@+id/progressBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="68dp"
        android:progressDrawable="@drawable/custom_progress"
        />
Hope this will help you.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜