Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Setting background with a selector in switch renderer displays two switches

$
0
0

I have a custom switch like
public class CustomSwitch : Switch
{
public CustomSwitch ()
{
}
}

and when i write a renderer for this switch to change button drawable using android selector

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.SetButtonDrawable (Resource.Drawable.toggle_button_selector);

        }
    }
}

Two switches are displayed one is default and another based on selector...

Please suggest what i am doing wrong.
Any help is highly appreciated.


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>