Forum Xamarin Xamarin.Forms

SwitchRenderer: Setting Disabled, Focused Drawables?

IanVinkIanVink CAInsider, University ✭✭✭

In the following custom switch renderer, the background is nicely changed. I can't find in the API how to set the switch's Disabled and Focused values in general for the background and thumb??

I am trying to implement this XML style:

 [selector xmlns: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" /

[assembly: ExportRenderer(typeof(CustomSwitch), typeof(CustomSwitchRenderer))]
namespace Android.Renderers 
public class CustomSwitchRenderer   :  SwitchRenderer
    protected override void OnElementChanged(ElementChangedEventArgs<Switch> e)
        if (e.OldElement == null)
            Switch element = (Switch) this.Element;
            var native = (global::Android.Widget.Switch) Control;



  • Mdt87Mdt87 DEMember ✭✭
    edited February 2015

    Hello Ian,

    do you found a solution for it? I'm currently trying the same to implement a custom switch which looks similar on all devices.



  • IanVinkIanVink CAInsider, University ✭✭✭

    I went to and got the styles for a switch

Sign In or Register to comment.