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="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]

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

            native.SetBackgroundResource(CSI.Android.Resource.Drawable.apptheme_switch_bg_holo_light);
        }
    }
    }
}

Posts

  • 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.

    Thanks

    Martin

  • IanVinkIanVink CAInsider, University ✭✭✭

    I went to http://android-holo-colors.com and got the styles for a switch

Sign In or Register to comment.