一个seekBar由三个图片组成:stride_bg.png, seekBar_bg.png, thumb.png
图片素材制作:stride_bg.png, seekBar_bg.png要做成上沿和下沿都是透明的。
stride_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:src="@drawable/stride_bg_2" android:tileMode="repeat"
android:antialias="true" android:dither="false" android:filter="false"
android:gravity="left" />
</clip>
</item>
</layer-list>
thumb的XML
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 按下状态 -->
<item
android:state_pressed="true"
android:drawable="@drawable/anchor_3"
/>
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/anchor_3"
/>
</selector>
seekBar的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">
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/play_bar_1" android:tileMode="repeat"
android:antialias="true" android:dither="false" android:filter="false"
android:gravity="left" />
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient
android:startColor="#80028ac8"
android:centerColor="#80127fb1"
android:centerY="0.75"
android:endColor="#a004638f"
android:angle="270"
/>
</shape>
</clip>
</item>
<item
android:id="@android:id/progress"
android:drawable="@drawable/seekbar_progress_bg"
/>
</layer-list>
定义Custom的SeekBar XML
<SeekBar android:id="@+id/Seek_Bar" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="center_vertical"
android:minHeight="19dip" android:maxHeight="19dip"
android:layout_weight="1" android:progressDrawable="@drawable/seekbar_progress"
android:paddingLeft="10dip" android:paddingRight="8dip"
android:thumb="@drawable/seek_thumb"/>
参考:
http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/
http://developer.android.com/guide/topics/resources/drawable-resource.html