首先创建lay-list的布局文件:seekbar_style.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/seekbar_bg">
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<gradient android:startColor="#434343" android:endColor="#434343"></gradient>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<gradient android:startColor="#26ddd0" android:endColor="#26ddd0"></gradient>
</shape>
</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_focused="true"
android:state_pressed="true"
android:drawable="@drawable/thumb_pressed" />
<!-- 普通无焦点状态 -->
<item
android:state_focused="false"
android:state_pressed="false"
android:drawable="@drawable/thumb_pressed" />
<!-- 有焦点状态-->
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/thumb_pressed" />
<!-- 有焦点 -->
<item
android:state_focused="true"
android:drawable="@drawable/thumb_pressed" />
</selector>
最后在布局文件中使用:
<SeekBar
android:id="@+id/media_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="9dp"
android:maxHeight="9dp"
android:progressDrawable="@drawable/seekbar_style"
android:thumb="@drawable/thumb"
android:layout_weight="1" />