系统默认的seekbar很多时候不符合开发需求,那么就需要自定义seekbar的样式,方法并不复杂,下面记录一下:
布局文件中:
android:thumb="@drawable/sanjiaoup"
通过这样一行代码就可以更换滑动图标,图片自己选择合适的就行。
自定义进度条布局文件中加入这个:
android:progressDrawable="@drawable/seekbar_style"
自定义drawable中加入layer-list
<?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="1000dip" />
<!-- startColor表示开始颜色,endColor表示结束颜色,centerColor表示中心颜色,3者结合成进度条颜色效果 -->
<!-- centerY表示进度条的粗细,越小的话越粗,越大则越细 -->
<gradient
android:angle="270"
android:centerColor="#005a5d5a"
android:centerY="0.75"
android:endColor="#000000"
android:startColor="#00ffffff" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:angle="270"
android:centerColor="#00ffb600"
android:centerY="0.75"
android:endColor="#00ffcb00"
android:startColor="#00ffd300" />
</shape>
</clip>
</item>
这里是滑动过后的样式
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="100dip" />
<gradient
android:angle="270"
android:centerColor="#fc0000"
android:centerY="0.75"
android:endColor="#fc0000"
android:startColor="#fc0000" />
</shape>
</clip>
</item>
</layer-list>
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。