Android 自定义SeekBar背景样式

自定义Android系统控件的背景样式大同小异,现在以自定义SeekBar背景样式走下流程:

 1.SeekBar的进度条样式,custom_seekbar_progress.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>
            <solid android:color="#9e9e9e"/>
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#e4017f"/>
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <solid android:color="#9e9e9e"/>
            </shape>
        </clip>
    </item>

</layer-list>

这里是以自定义的颜色作为进度条背景,如果要使用图片资源,那就这样:

 <item
            android:id="@android:id/background"
            android:drawable="@drawable/seekbar_progess">
 </item>
 2.SeekBar的滑块样式custom_seekbar_thumb.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/seekbar_thumb_normal"
          android:state_focused="true" android:state_pressed="false"/>

    <item android:drawable="@drawable/seekbar_thumb_pressed"
          android:state_focused="true" android:state_pressed="true"/>

    <item android:drawable="@drawable/seekbar_thumb_pressed"
          android:state_focused="false"
          android:state_pressed="true"/>

    <item android:drawable="@drawable/seekbar_thumb_normal"/>

</selector>

分别定义按下状态与松开状态下的图片.

最后在SeekBar中使用我们自定义的属性:

<SeekBar
        android:maxHeight="3dpt"
        android:minHeight="3dp"
        android:progressDrawable="@drawable/custom_seekbar_progress"
        android:thumb="@drawable/custom_seekbar_thumb"
        ....../>

maxHeigh,minHeigh 用来指定进度条的高度.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值