Search code examples
androidseekbar

How can i change the color of seekbar


I need a seek bar which color need this

enter image description here

I made an xml file in drawable and its gradient is set below

 <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="#808080"
            android:centerY="0.75"
            android:endColor="#808080"
            android:startColor="#808080" />
    </shape>
</item>
<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="2dip" />

            <gradient
                android:angle="270"
                android:centerColor="#09488D"
                android:centerY="0.75"
                android:endColor="#09488D"
                android:startColor="#09488D" />
        </shape>
    </clip>
</item>
<item android:id="@android:id/progress">
    <clip>
        <shape>
            <corners android:radius="5dip" />

            <gradient
                android:angle="270"
                android:centerColor="#09488D"
                android:centerY="0.75"
                android:endColor="#09488D"
                android:startColor="#09488D" />
        </shape>
    </clip>
 </item>

</layer-list>

Then this xml use it in seekbar's background But the color does not change :(


Solution

  • Include this in seek bar:

                <SeekBar 
                    android:progressDrawable="@drawable/progress"
                    android:thumb="@drawable/thumb"/>
    

    where 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" 
        android:drawable="@drawable/background_fill" />
    
    <item android:id="@android:id/progress">
        <clip android:drawable="@drawable/progress_fill" />
    </item>
    </layer-list>
    

    and thumb.xml:

    <?xml version="1.0" encoding="utf-8"?>    
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
       <item android:drawable="@drawable/thumb_fill" />
    </selector>
    

    Also you can refer this link - http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/ and http://www.anddev.org/seekbar_progressbar_customizing-t6083.html