protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); thisButton = Control as Android.Widget.Button; if (thisButton != null) { thisButton.SetMaxLines(1); thisButton.Ellipsize = TruncateAt.End; } List <string> classes = Element.GetValue(ResponsiveProperty.ClassProperty)?.ToString().Split(" ".ToCharArray()).ToList(); if (classes != null) { ProcessButtonTheme(classes); ProcessButtonSize(classes); } var padding = (Thickness)Element.GetValue(ButtonProperty.PaddingProperty); if (padding.Left != -100 && padding.Top != -100 && padding.Right != -100 && padding.Bottom != -100) { int top = int.Parse(padding.Top.ToString()); int left = int.Parse(padding.Left.ToString()); int bottom = int.Parse(padding.Bottom.ToString()); int right = int.Parse(padding.Right.ToString()); thisButton.SetPadding(left, top, right, bottom); Element.HeightRequest = Element.FontSize + padding.VerticalThickness + 10; } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); thisButton = Control as Android.Widget.Button; if (thisButton != null) { thisButton.SetMaxLines(1); thisButton.Ellipsize = TruncateAt.End; } List <string> classes = Element.GetValue(ResponsiveProperty.ClassProperty)?.ToString().Split(" ".ToCharArray()).ToList(); if (classes != null) { ProcessButtonTheme(classes); ProcessButtonSize(classes); } //Handle Button Pading var padding = (Thickness)Element.GetValue(ButtonProperty.PaddingProperty); if (padding.Left != -100 && padding.Top != -100 && padding.Right != -100 && padding.Bottom != -100) { int top = int.Parse(padding.Top.ToString()); int left = int.Parse(padding.Left.ToString()); int bottom = int.Parse(padding.Bottom.ToString()); int right = int.Parse(padding.Right.ToString()); thisButton.SetPadding(left, top, right, bottom); Element.HeightRequest = Element.FontSize + padding.VerticalThickness + 10; } // Handle PressedBackgroundColor pressedBackgroundColor = (Xamarin.Forms.Color)Element.GetValue(ButtonProperty.PressedBackgroundColorProperty); if (!pressedBackgroundColor.Equals(Color.Default)) { originalBackgroundColor = Element.BackgroundColor; //Handle TextColor pressedTextColor = (Xamarin.Forms.Color)Element.GetValue(ButtonProperty.PressedTextColorProperty); if (!pressedTextColor.Equals(Color.Default)) { originalTextColor = Element.TextColor; } thisButton.Touch += ButtonTouched; thisButton.SetSingleLine(true); isToggleButton = Convert.ToBoolean(Element.GetValue(ButtonProperty.IsToggleButtonProperty)); } // Handle Horizontal Content Alignment var horizontalContentAlignment = (ButtonProperty.HorizontalContentAlignmentType)Element.GetValue(ButtonProperty.HorizontalContentAlignmentProperty); if (horizontalContentAlignment != ButtonProperty.HorizontalContentAlignmentType.PlatformDefault) { switch (horizontalContentAlignment) { case ButtonProperty.HorizontalContentAlignmentType.Fill: thisButton.Gravity = thisButton.Gravity | GravityFlags.FillHorizontal; break; case ButtonProperty.HorizontalContentAlignmentType.Left: thisButton.Gravity = thisButton.Gravity | GravityFlags.Left; break; case ButtonProperty.HorizontalContentAlignmentType.Right: thisButton.Gravity = thisButton.Gravity | GravityFlags.Right; break; case ButtonProperty.HorizontalContentAlignmentType.Centre: thisButton.Gravity = thisButton.Gravity | GravityFlags.CenterHorizontal; break; } } // Handle Vertical Content Alignment var verticalContentAlignment = (ButtonProperty.VerticalContentAlignmentType)Element.GetValue(ButtonProperty.VerticalContentAlignmentProperty); if (verticalContentAlignment != ButtonProperty.VerticalContentAlignmentType.PlatformDefault) { switch (verticalContentAlignment) { case ButtonProperty.VerticalContentAlignmentType.Fill: thisButton.Gravity = thisButton.Gravity | GravityFlags.FillVertical; break; case ButtonProperty.VerticalContentAlignmentType.Top: thisButton.Gravity = thisButton.Gravity | GravityFlags.Top; break; case ButtonProperty.VerticalContentAlignmentType.Bottom: thisButton.Gravity = thisButton.Gravity | GravityFlags.Bottom; break; case ButtonProperty.VerticalContentAlignmentType.Centre: thisButton.Gravity = thisButton.Gravity | GravityFlags.CenterVertical; break; } } }