AView CreateSwipeItem(SwipeItem formsSwipeItem)
        {
            var swipeButton = new AButton(_context)
            {
                Background = new ColorDrawable(formsSwipeItem.BackgroundColor.ToAndroid()),
                Text       = formsSwipeItem.Text ?? string.Empty
            };

            var textColor = GetSwipeItemColor(formsSwipeItem.BackgroundColor);

            swipeButton.SetTextColor(textColor.ToAndroid());
            swipeButton.TextAlignment = ATextAlignment.Center;

            int contentHeight = _contentView.Height;
            int contentWidth  = (int)_context.ToPixels(SwipeItemWidth);
            int iconSize      = formsSwipeItem.IconImageSource != null?Math.Min(contentHeight, contentWidth) / 2 : 0;

            _ = this.ApplyDrawableAsync(formsSwipeItem, MenuItem.IconImageSourceProperty, Context, drawable =>
            {
                drawable.SetBounds(0, 0, iconSize, iconSize);
                drawable.SetColorFilter(textColor.ToAndroid(), FilterMode.SrcAtop);
                swipeButton.SetCompoundDrawables(null, drawable, null, null);
            });

            var textSize      = !string.IsNullOrEmpty(swipeButton.Text) ? (int)swipeButton.TextSize : 0;
            var buttonPadding = (contentHeight - (iconSize + textSize + 6)) / 2;

            swipeButton.SetPadding(0, buttonPadding, 0, buttonPadding);
            swipeButton.SetOnTouchListener(null);

            return(swipeButton);
        }
Example #2
0
        AView CreateSwipeItem(SwipeItem formsSwipeItem)
        {
            var swipeButton = new AButton(_context)
            {
                Background = new ColorDrawable(formsSwipeItem.BackgroundColor.ToAndroid()),
                Text       = formsSwipeItem.Text ?? string.Empty
            };

            if (!string.IsNullOrEmpty(formsSwipeItem.AutomationId))
            {
                swipeButton.ContentDescription = formsSwipeItem.AutomationId;
            }

            var textColor = GetSwipeItemColor(formsSwipeItem.BackgroundColor);

            swipeButton.SetTextColor(textColor.ToAndroid());
            swipeButton.TextAlignment = ATextAlignment.Center;

            int contentHeight = _contentView.Height;
            int contentWidth  = (int)_context.ToPixels(SwipeItemWidth);
            int iconSize      = formsSwipeItem.IconImageSource != null?Math.Min(contentHeight, contentWidth) / 2 : 0;

            _ = this.ApplyDrawableAsync(formsSwipeItem, MenuItem.IconImageSourceProperty, Context, drawable =>
            {
                int drawableWidth  = drawable.IntrinsicWidth;
                int drawableHeight = drawable.IntrinsicHeight;

                if (drawableWidth > drawableHeight)
                {
                    var iconWidth  = iconSize;
                    var iconHeight = drawableHeight * iconWidth / drawableWidth;
                    drawable.SetBounds(0, 0, iconWidth, iconHeight);
                }
                else
                {
                    var iconHeight = iconSize;
                    var iconWidth  = drawableWidth * iconHeight / drawableHeight;
                    drawable.SetBounds(0, 0, iconWidth, iconHeight);
                }

                drawable.SetColorFilter(textColor.ToAndroid(), FilterMode.SrcAtop);
                swipeButton.SetCompoundDrawables(null, drawable, null, null);
            });

            var textSize      = !string.IsNullOrEmpty(swipeButton.Text) ? (int)swipeButton.TextSize : 0;
            var buttonPadding = (contentHeight - (iconSize + textSize + 6)) / 2;

            swipeButton.SetPadding(0, buttonPadding, 0, buttonPadding);
            swipeButton.SetOnTouchListener(null);
            swipeButton.Visibility = formsSwipeItem.IsVisible ? ViewStates.Visible : ViewStates.Gone;

            if (!string.IsNullOrEmpty(formsSwipeItem.AutomationId))
            {
                swipeButton.ContentDescription = formsSwipeItem.AutomationId;
            }

            return(swipeButton);
        }
Example #3
0
 public static void UpdateColor(this AndroidX.AppCompat.Widget.AppCompatButton button, Color color, ColorStateList?defaultColor)
 {
     if (color.IsDefault)
     {
         button.SetTextColor(defaultColor);
     }
     else
     {
         button.SetTextColor(color.ToNative());
     }
 }
Example #4
0
 public static void UpdateLineBreakMode(this AButton nativeControl, Button button)
 {
     nativeControl.SetLineBreakMode(button.LineBreakMode);
 }