0

I am having trouble changing the style of a Switch view in my project and can't figure out what I am doing wrong or missing... My project uses holo everywhere.

I can't change the text, the thumb or the track. I've tried applying android:thumb and android:track drawables directly from the xml but nothing changes. Not even the android:textOff and android:textOn have any effect.

I found a great post on how to customise the android Switch view style and looked through all the code but couldn't find anything I was doing wrong: http://custom-android-dn.blogspot.co.uk/2013/01/how-to-use-and-custom-switch-in-android.html

Really not sure what else to try.

Here is the xml code:

    <Switch
        android:id="@+id/home_availability_switch"
        style="@style/MySwitch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:enabled="true"
        android:focusable="true"
        android:textOff="Free"
        android:textOn="Busy" />

Here is the style:

<style name="MySwitch" parent="@style/Holo.Switch.Light">
    <item name="android:thumb">@drawable/selector_availability_switch_thumb</item>
    <item name="android:track">@drawable/selector_availability_switch_background</item>
</style>

Here is the thumb selector (these are default system drawables. i have tried with different drawables):

<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_disabled_holo_light" android:state_enabled="false"/>
<item android:drawable="@drawable/switch_thumb_holo_dark"/>

Here is the track selector (these are default system drawables. i have tried with different drawables):

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

I also found this post How can I style an Android Switch? and follow the instructions but had no luck.

Any one else had a similar experience when using Holo Everywhere?

Community
  • 1
  • 1
speedynomads
  • 2,632
  • 1
  • 26
  • 24

1 Answers1

2

You need to define the switch like this. Need the whole package name in there for it to work.

<org.holoeverywhere.widget.Switch
    android:id="@+id/lockSwitch"
    style="?switchStyleOld"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TestSwitch" />

Hope this helps.

Aswin Rajendiran
  • 3,399
  • 1
  • 21
  • 18