android之4.0控件switch自定义开关滑块、滑块轨道和宽度

</pre><pre style="font-family:宋体; font-size:9.6pt; background-color:rgb(255,255,255)">区分一下概念:
1.android:background view背景
2.android:thumb 滑块 有选中状态 android:state_checked
3.android:track 滑块的轨道 有选中状态 android:state_checked

 
<Switch
    android:id="@+id/customer_gender"
    style="@style/widget_gender_switch" />


<style name="widget_gender_switch">

        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:textOff">""</item><!-- 此设置不使用文字,只用背景图的状态来表示开关 -->
        <item name="android:textOn">""</item>
        <item name="android:thumb">@drawable/widget_gender_thumb</item><!--滑块图,改变 选中状态来表示开关-->
        <item name="android:thumbTextPadding">10dp</item><!-- 用来控制滑块和文字之间的间距来控制switch整体宽度 -->
        <item name="android:track">@drawable/widget_gender_track</item><!--滑块轨道,改变选中状态来表示开关-->

    </style>


widget_gender_track.xml

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

    <!-- 开始按钮 -->
    <item android:drawable="@drawable/track_checked_interview" android:state_checked="true" />
    <item android:drawable="@drawable/track_nor_interview" />

</selector>


widget_gender_thumb.xml


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/abc_btn_switch_to_on_mtrl_00012" />
    <item android:drawable="@drawable/abc_btn_switch_to_on_mtrl_00001" />
</selector>


参考http://stackoverflow.com/questions/20762490/how-to-change-height-and-width-of-switch-in-android

http://stackoverflow.com/questions/10173590/how-to-change-the-size-of-a-switch-widget



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值