protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Label> e) { base.OnElementChanged(e); if (e.OldElement == null) { //Only enable hardware accelleration on lollipop if ((int)Android.OS.Build.VERSION.SdkInt < 21) { SetLayerType(LayerType.Software, null); } } if (!string.IsNullOrEmpty(((IconAwesomeLabelBase)Element).Icon)) { Control.Typeface = Typeface.CreateFromAsset(context.Assets, IconExtensions.FindNameFileForFont(((IconAwesomeLabelBase)Element).TypeIcon)); IIcon icon = IconExtensions.FindIconForKey(((IconAwesomeLabelBase)Element).Icon); Element.Text = $"{icon.Character}"; } else { Control.Typeface = Typeface.Create(Element.FontFamily, TypefaceStyle.Normal); Element.Text = ((IconAwesomeLabelBase)Element).Text; } }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { //Only enable hardware accelleration on lollipop if ((int)Android.OS.Build.VERSION.SdkInt < 21) { SetLayerType(LayerType.Software, null); } } if (!string.IsNullOrEmpty(((IconAwesomeButtonBase)Element).Icon)) { Control.Typeface = Typeface.CreateFromAsset(context.Assets, IconExtensions.FindNameFileForFont(((IconAwesomeButtonBase)Element).TypeIcon)); IIcon icon = IconExtensions.FindIconForKey(((IconAwesomeButtonBase)Element).Icon); Element.Text = $"{icon.Character}"; } else { Control.Typeface = Typeface.Create(Element.FontFamily, TypefaceStyle.Normal); Element.Text = ((IconAwesomeButtonBase)Element).Text; } if (((IconAwesomeButtonBase)Element).ImageSource != null) { Android.Widget.Button thisButton = Control as Android.Widget.Button; thisButton.Touch += (object sender, Android.Views.View.TouchEventArgs e2) => { if (e2.Event.Action == MotionEventActions.Down) { Control.SetBackgroundColor(Element.BackgroundColor.ToAndroid()); } else if (e2.Event.Action == MotionEventActions.Up) { Control.SetBackgroundColor(Element.BackgroundColor.ToAndroid()); Control.SetShadowLayer(0, 0, 0, Android.Graphics.Color.Transparent); Control.CallOnClick(); } }; } }