</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>
<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