Esempio n. 1
0
        internal static void UpdateBorderDrawable(this AppCompatRadioButton platformView, IRadioButton radioButton)
        {
            BorderDrawable?mauiDrawable = platformView.Background as BorderDrawable;

            if (mauiDrawable == null)
            {
                mauiDrawable = new BorderDrawable(platformView.Context);

                platformView.Background = mauiDrawable;
            }

            mauiDrawable.SetBackground(radioButton.Background);

            if (radioButton.StrokeColor != null)
            {
                mauiDrawable.SetBorderBrush(new SolidPaint {
                    Color = radioButton.StrokeColor
                });
            }

            if (radioButton.StrokeThickness > 0)
            {
                mauiDrawable.SetBorderWidth(radioButton.StrokeThickness);
            }

            if (radioButton.CornerRadius > 0)
            {
                mauiDrawable.SetCornerRadius(radioButton.CornerRadius);
            }
        }
Esempio n. 2
0
        internal static void UpdateBorderDrawable(this MaterialButton platformView, IButton button)
        {
            var background = button.Background;

            if (!background.IsNullOrEmpty())
            {
                // Remove previous background gradient if any
                if (platformView.Background is BorderDrawable previousBackground)
                {
                    platformView.Background = null;
                    previousBackground.Dispose();
                }

                var mauiDrawable = new BorderDrawable(platformView.Context);

                // Null out BackgroundTintList to avoid that the MaterialButton custom background doesn't get tinted.
                platformView.BackgroundTintList = null;

                platformView.Background = mauiDrawable;

                mauiDrawable.SetBackground(background);

                if (button.StrokeColor != null)
                {
                    mauiDrawable.SetBorderBrush(new SolidPaint {
                        Color = button.StrokeColor
                    });
                }

                if (button.StrokeThickness > 0)
                {
                    mauiDrawable.SetBorderWidth(button.StrokeThickness);
                }

                if (button.CornerRadius > 0)
                {
                    mauiDrawable.SetCornerRadius(button.CornerRadius);
                }
                else
                {
                    const int defaultCornerRadius = 2;                     // Default value for Android material button.
                    mauiDrawable.SetCornerRadius(platformView.Context.ToPixels(defaultCornerRadius));
                }
            }
        }