Android APP開發活用範例速查大辭典(Ch0111-利用XML自訂ToggleButton)
GUI-XML
<?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:gravity=”center” android:orientation=”vertical” >
<View android:layout_width=”wrap_content” android:layout_height=”0dp” android:layout_weight=”1″ />
<ToggleButton android:id=”@+id/ToggleButton” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:background=”@drawable/ch0112_selector_toggle_background” />
<View android:layout_width=”wrap_content” android:layout_height=”0dp” android:layout_weight=”1″ />
<Switch android:id=”@+id/Switch” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:thumb=”@drawable/ch0112_selector_switch_thumb” android:track=”@drawable/ch0112_selector_switch_background” />
<View android:layout_width=”wrap_content” android:layout_height=”0dp” android:layout_weight=”1″ />
</LinearLayout>
|
xml-ch0112_selector_toggle_background
<?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”>
<item android:drawable=”@color/FlatLightAqua” android:state_checked=”false”/> <item android:drawable=”@color/FlatLightPink” android:state_checked=”true”/>
</selector>
|
xml-ch0112_selector_switch_thumb
<?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”>
<item android:drawable=”@drawable/switch_thumb_disabled_holo_light” android:state_enabled=”false”/> <item android:drawable=”@drawable/switch_thumb_pressed_holo_light” android:state_pressed=”true”/> <item android:drawable=”@drawable/switch_thumb_activated_holo_light” android:state_checked=”true”/> <item android:drawable=”@drawable/switch_thumb_holo_light”/>
</selector>
|
xml-ch0112_selector_switch_background
<?xml version=”1.0″ encoding=”utf-8″?> <selector xmlns:android=”http://schemas.android.com/apk/res/android”>
<item android:drawable=”@drawable/switch_bg_disabled_holo_dark” android:state_enabled=”false”/> <item android:drawable=”@drawable/switch_bg_focused_holo_dark” android:state_focused=”true”/> <item android:drawable=”@drawable/switch_bg_holo_dark”/>
</selector>
|