custom seekbar.png
<SeekBar
android:layout_width="match_parent"
android:layout_height="40dp"
android:max="100"
android:maxHeight="10dp"
android:progress="40"
android:progressDrawable="@drawable/seekbar_bg"
android:secondaryProgress="60"
android:splitTrack="false"
android:thumb="@drawable/seekbar_thumb"/>
關(guān)鍵屬性:
android:maxHeight
背景高度
android:progressDrawable
進(jìn)度條背景
android:thumb
進(jìn)度thumb(拖塊)
android:splitTrack
thumb是否切割seekbar背景,默認(rèn)true,會(huì)看到thumb周圍區(qū)域被切割晶衷,效果如下(為了效果明顯乡小,背景高度特意改高了)
image.png
seekbar_bg.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">
<shape>
<corners android:radius="5dp" />
<solid android:color="#90A4AE" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dp" />
<solid android:color="#FFEB3B" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dp" />
<solid android:color="#2196F3" />
</shape>
</clip>
</item>
</layer-list>
seekbar_thumb.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape android:shape="oval">
<solid android:color="#FF5722" />
<size android:width="30dp" android:height="30dp" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#3F51B5" />
<size android:width="30dp" android:height="30dp" />
</shape>
</item>
</selector>
android:thumbTint
可以不指定android:thumb 指定 android:thumbTint來(lái)改變thumb顏色心墅,按下/點(diǎn)擊有系統(tǒng)默認(rèn)動(dòng)效偎捎。
<SeekBar
android:layout_width="match_parent"
android:layout_height="40dp"
android:max="100"
android:maxHeight="10dp"
android:progress="40"
android:progressDrawable="@drawable/seekbar_bg"
android:secondaryProgress="60"
android:splitTrack="false"
android:thumbTint="#FF5722" />
android:thumbTint
前后間距問(wèn)題:
android:paddingStart="0dp"
android:paddingEnd="0dp"
reference:
http://www.zoftino.com/android-seekbar-and-custom-seekbar-examples