Friday, March 16, 2012

Custom Seekbar Tutorial


seekbar_progress_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <clip >
            <bitmap
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:antialias="true"
                android:dither="false"
                android:filter="false"
                android:gravity="left"
                android:src="@drawable/green">
             </bitmap>
        </clip>
    </item>
</layer-list>



seekbar_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">
         <nine-patch
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:dither="true"
            android:src="@drawable/whitepatch">
          </nine-patch>
    </item>
    <item android:id="@android:id/secondaryProgress">
           <clip >
               <shape >
                  <gradient
                    android:angle="270"
                    android:centerColor="#80127fb1"
                    android:centerY="0.75"
                    android:endColor="#a004638f"
                    android:startColor="#80028ac8">
                   </gradient>
              </shape>
           </clip>
     </item>
     <item
             android:id="@android:id/progress"
             android:drawable="@drawable/seekbar_progress_bg">
     </item>
</layer-list>





XML

<SeekBar
                                android:id="@+id/seekbar_bar"
                                style="?android:attr/progressBarStyleHorizontal"
                                android:layout_width="420dip"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="0dip"
                                android:layout_marginTop="12dip"
                                android:maxHeight="9dp"
                                android:minHeight="9dp"
                                android:progressDrawable="@drawable/seekbar_progress"
                                android:thumb="@drawable/shine_btn" />

green.png

shine_btn.png
whitepatch.9.png

No comments: