protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Switch> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } view = (ThumbColorChangeableSwitch)Element; if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) { if (this.Control != null) { if (this.Control.Checked) { this.Control.TrackDrawable.SetColorFilter(view.SwitchOnColor.ToAndroid(), PorterDuff.Mode.SrcAtop); } else { this.Control.TrackDrawable.SetColorFilter(view.SwitchOffColor.ToAndroid(), PorterDuff.Mode.SrcAtop); } this.Control.CheckedChange += this.OnCheckedChange; UpdateSwitchThumbImage(view); } //Control.TrackDrawable.SetColorFilter(view.SwitchBGColor.ToAndroid(), PorterDuff.Mode.Multiply); } }
private void UpdateSwitchThumbImage(ThumbColorChangeableSwitch view) { if (!string.IsNullOrEmpty(view.SwitchThumbImage)) { view.SwitchThumbImage = view.SwitchThumbImage.Replace(".jpg", "").Replace(".png", ""); int imgid = (int)typeof(Resource.Drawable).GetField(view.SwitchThumbImage).GetValue(null); Control.SetThumbResource(Resource.Drawable.bike); } else { Control.ThumbDrawable.SetColorFilter(view.SwitchThumbColor.ToAndroid(), PorterDuff.Mode.Multiply); // Control.SetTrackResource(Resource.Drawable.track); } }
protected override void OnElementChanged(ElementChangedEventArgs <Switch> e) { base.OnElementChanged(e); if (e.OldElement != null || e.NewElement == null) { return; } ThumbColorChangeableSwitch s = Element as ThumbColorChangeableSwitch; UISwitch sw = new UISwitch(); sw.ThumbTintColor = s.SwitchThumbColor.ToUIColor(); sw.OnTintColor = s.SwitchOnColor.ToUIColor(); SetNativeControl(sw); }