温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

自定义SeekBar样式

发布时间:2020-07-30 03:53:45 来源:网络 阅读:1495 作者:IT学无止境 栏目:移动开发

系统默认的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>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI