본문 바로가기

Dev_안드로이드/참고소스

Switch 스타일 변경

<Switch
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:thumb="@drawable/switch_thumb"
    android:track="@drawable/switch_bg" />




switch_thumb.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_enabled="false" android:drawable="@drawable/switch_thumb_disabled_holo_light" />
   <item android:state_pressed="true"  android:drawable="@drawable/switch_thumb_pressed_holo_light" />
   <item android:state_checked="true"  android:drawable="@drawable/switch_thumb_activated_holo_light" />
   <item                               android:drawable="@drawable/switch_thumb_holo_light" />
</selector>


drawable-xxhdpi 






switch_bg.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:drawable="@drawable/switch_bg_disabled_holo_dark" />
    <item android:state_focused="true"  android:drawable="@drawable/switch_bg_focused_holo_dark" />
    <item                               android:drawable="@drawable/switch_bg_holo_dark" />
</selector>



drawable-xxhdpi 



텍스트 색상변경

<style name="SwitchTextAppearance" parent="@android:style/TextAppearance.Holo.Small">
    <item name="android:textColor">@color/my_switch_color</item>
</style>


android:switchTextAppearance="@style/SwitchTextAppearance"



출처 : http://stackoverflow.com/questions/10118050/how-can-i-style-an-android-switch

  http://stackoverflow.com/questions/12706874/how-to-change-textcolor-of-switch-in-android