protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // get a copy of the xamarin control we are changing
            SelectImageButton formControl = (SelectImageButton)sender;

            // get the selected state and hold colors and widths and set them to be used thoughout the renderer
            droidBackgroundColor = formControl.BackgroundColor.ToAndroid();
            droidBorderColor     = formControl.BorderColor.ToAndroid();
            droidBorderWidth     = formControl.BorderWidth * 2;

            droidHoldBackgroundColor = formControl.HoldBackgroundColor.ToAndroid();
            droidHoldBorderColor     = formControl.HoldBorderColor.ToAndroid();
            droidHoldBorderWidth     = formControl.HoldBorderWidth * 2;

            base.OnElementPropertyChanged(formControl, e);

            // test of setting the padding for this before drawing a background
            this.SetClipChildren(true);

            // create a drawable color and set irs raduis, color, and border
            var rad = new global::Android.Graphics.Drawables.GradientDrawable();

            rad.SetCornerRadius(1000.00F);
            rad.SetColor(droidBackgroundColor);
            rad.SetStroke(droidBorderWidth, droidBorderColor);
            // apply the drawable to the background
            this.Background = rad;

            // set the draw border
            drawBorderWidth = (float)formControl.BorderWidth * 2;
        }
Beispiel #2
0
        void UpdateBackgroundColor()
        {
            var colorToSet = Element.Color;

            if (colorToSet == Color.Default)
            {
                colorToSet = Element.BackgroundColor;
            }
            Background = new global::Android.Graphics.Drawables.GradientDrawable();
            BackgroundGradient?.SetColor(colorToSet.ToAndroid());
        }
        //adding an android touch recogniser that can detect more touch and hold events than the forms one
        public override bool OnTouchEvent(MotionEvent e)
        {
            // this boolean will be used to decide on the colors at the end and set by the various touch event types
            bool touchDown = false;

            // color values to chnage on hold or relese
            Android.Graphics.Color touchBackgroundColor = droidBackgroundColor;
            Android.Graphics.Color touchBorderColor     = droidBorderColor;
            int touchBorderWidth;

            if (e.Action == MotionEventActions.Down)
            {
                touchDown = true;
            }
            if (e.Action == MotionEventActions.Up)
            {
                touchDown = false;
            }
            if (e.Action == MotionEventActions.ButtonPress)
            {
                touchDown = false;
            }
            if (e.Action == MotionEventActions.ButtonRelease)
            {
                touchDown = false;
            }

            // set the color depebding on the pressed state of the button
            if (touchDown)
            {
                touchBackgroundColor = droidHoldBackgroundColor;
                touchBorderColor     = droidHoldBorderColor;
                touchBorderWidth     = droidHoldBorderWidth;
            }
            else
            {
                touchBackgroundColor = droidBackgroundColor;
                touchBorderColor     = droidBorderColor;
                touchBorderWidth     = droidBorderWidth;
            }

            // create a drawable color and set its radius, color, and border
            var rad = new global::Android.Graphics.Drawables.GradientDrawable();

            rad.SetCornerRadius(1000.00F);
            rad.SetColor(touchBackgroundColor);
            rad.SetStroke(touchBorderWidth, touchBorderColor);
            // apply the drawable to the background
            this.Background = rad;
            return(base.OnTouchEvent(e));
        }
Beispiel #4
0
 public RoundedBoxViewRenderer()
 {
     AutoPackage = false;
     Background  = new global::Android.Graphics.Drawables.GradientDrawable();
 }