我創建了一個基本的自定義Switch
,如下所述。自定義Android切換軌道'動畫'
<Switch
android:id="@+id/availSwitch"
android:layout_width="wrap_content"
android:switchMinWidth="110dp"
android:layout_height="wrap_content"
android:track="@drawable/switch_track"
android:thumb="@drawable/thumb"/>
@drawable/thumb
是一個簡單的PNG,它工作正常。
@drawable/switch_track
定義如下。 @drawable/trackon
和@drawable/trackoff
是PNG的。
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="false" android:drawable="@drawable/trackoff" />
<item android:state_checked="true" android:drawable="@drawable/trackon" />
<item android:drawable="@drawable/trackoff" />
</selector>
此開關看起來和預期大部分工作,但有一些方法來「動畫」軌道爲拇指行駛在其上的用戶拖動?或者在選中或取消選中之間淡入淡出,或者最好在拇指後面改變。
當前行爲如下所示。
更好地利用搜索條,使其custom..either使用的toogle –
http://stackoverflow.com/questions/9752760/slide-切換爲Android –
https://github.com/tuesda/SwitchBox –