void UpdateStyle() { var view = Control ?? Container; var bgColor = (Element as VisualElement)?.BackgroundColor ?? Color.Transparent; PaintDrawable paint = new PaintDrawable(bgColor.ToAndroid()); GradientDrawable gradient = new GradientDrawable(); paint.SetCornerRadius(Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.CornerRadiusProperty))); gradient.SetCornerRadius(Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.CornerRadiusProperty))); gradient.SetColor(Color.Transparent.ToAndroid()); gradient.SetOrientation(GradientDrawable.Orientation.LeftRight); gradient.SetShape(ShapeType.Rectangle); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { view.Elevation = Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.ShadowOffsetYProperty)); view.TranslationZ = Forms.Context.ToPixels((double)Element.GetValue(ViewEffect.ShadowOffsetYProperty)); } gradient.SetStroke((int)Forms.Context.ToPixels(ViewEffect.GetBorderWidth(Element)), ((Color)Element.GetValue(ViewEffect.BorderColorProperty)).ToAndroid()); LayerDrawable layer = new LayerDrawable( new Drawable[] { paint, gradient }); view.SetBackground(layer); }
private void UpdateStyle() { var view = Control ?? Container; _DefaultMaskToBounds = view.Layer.MasksToBounds; _DefaultBackgroundColor = view.BackgroundColor; if (_BorderLayer == null) { _BorderLayer = new CALayer(); view.Layer.InsertSublayer(_BorderLayer, 0); } _BorderLayer.Frame = new CGRect(CGPoint.Empty, view.Layer.Frame.Size); _BorderLayer.BorderWidth = (nfloat)ViewEffect.GetBorderWidth(Element); _BorderLayer.BorderColor = ViewEffect.GetBorderColor(Element).ToUIColor().CGColor; _BorderLayer.CornerRadius = (nfloat)ViewEffect.GetCornerRadius(Element); _BorderLayer.MasksToBounds = true; _BorderLayer.BackgroundColor = view.BackgroundColor.CGColor; view.BackgroundColor = UIColor.Clear; view.Layer.ShadowColor = ViewEffect.GetShadowColor(Element).ToUIColor().CGColor; view.Layer.ShadowRadius = (nfloat)ViewEffect.GetShadowRadius(Element); view.Layer.ShadowOpacity = ViewEffect.GetShadowOpacity(Element); view.Layer.ShadowOffset = new CGSize( (nfloat)ViewEffect.GetShadowOffsetX(Element), (nfloat)ViewEffect.GetShadowOffsetY(Element)); view.Layer.MasksToBounds = false; //Remove default border view.Layer.BorderWidth = 0; view.Layer.BorderColor = UIColor.Clear.CGColor; view.ClipsToBounds = false; }