1、宽度
seekbar显示宽度比设置的小,因为有内边距、将padding、paddingStart、paddingEnd设为0即可
2、样式
分为两部分
一、进度条样式(progressbar.xml)
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--3个层的顺序即为显示时的叠加顺序-->
<!--背景色-->
<item android:id="@android:id/background">
<shape>
<corners android:radius="1dp" />
<solid android:color="@color/colorGray" />
</shape>
</item>
<!--二级进度条的颜色-->
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="1dp" />
<solid android:color="@color/colorPrimaryDark" />
</shape>
</clip>
</item>
<!--一级进度条的颜色,也可以直接替换成图片-->
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="1dp" />
<solid android:color="@color/colorWhite" />
</shape>
</clip>
</item>
</layer-list>
二、按钮样式
1)seekbar_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="false" android:drawable="@drawable/thumb_shape" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/thumb_shape" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/thumb_shape" />
<item android:drawable="@drawable/thumb_shape" />
2)thumb_shape.xml(一个圆,solid填充色,size为大小,stroke为边框色)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorWhite" />
<size
android:width="5dp"
android:height="5dp" />
</shape>
三、使用自定义样式文件
<SeekBar
android:id="@+id/progressBar"
android:layout_width="365dp"
android:layout_height="5dp"
android:padding="0dp"
android:paddingEnd="0dp"
android:paddingStart="0dp"
android:maxHeight="1dp"
android:minHeight="1dp"
app:layout_constraintBottom_toBottomOf="@+id/view"
app:layout_constraintStart_toStartOf="@+id/view"
app:layout_constraintEnd_toEndOf="@+id/view"
app:layout_constraintTop_toBottomOf="@+id/remark"
android:progressDrawable="@drawable/progressbar"
android:thumb="@drawable/seekbar_thumb"/>