使抽屜文件夾內水庫
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/toggle_on" android:state_checked="true" android:state_pressed="true"/>
<item android:drawable="@drawable/toggle_on" android:state_checked="true" android:state_focused="false"/>
<item android:drawable="@drawable/toggle_off" android:state_checked="false" android:state_pressed="true"/>
<item android:drawable="@drawable/toggle_off" android:state_checked="false" android:state_focused="false"/>
</selector>
然後在XML
<Switch
android:id="@+id/saveLoginCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn=""
android:textOff=""
android:text=""
android:background="@drawable/toggle_selector"
android:thumb="@android:color/transparent"
android:track="@android:color/transparent"
/>
爲什麼有巨大的空間在這裏的android做到這一點:textOff = 「 」 機器人:紋元=「」? – Piyush
http://stackoverflow.com/questions/10118050/how-can-i-style-an-android-switch 看看這個鏈接..我認爲這將有助於。 –
嘗試android:button =「@ null」 – NullPointerException