예제 #1
0
        private void ChangeColor(Color newColor)
        {
            _tabs.IndicatorColor = newColor;

            // change ActionBar color just if an ActionBar is available
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Honeycomb)
            {
                Drawable      colorDrawable  = new ColorDrawable(newColor);
                Drawable      bottomDrawable = Resources.GetDrawable(Resource.Drawable.actionbar_bottom);
                LayerDrawable ld             = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable });

                if (_oldBackground == null)
                {
                    if ((int)Build.VERSION.SdkInt < 17)
                    {
                        ld.Callback = _drawableCallback;
                    }
                    else
                    {
                        ActionBar.SetBackgroundDrawable(ld);
                    }
                }
                else
                {
                    TransitionDrawable td = new TransitionDrawable(new Drawable[] { _oldBackground, ld });

                    // workaround for broken ActionBarContainer drawable handling on
                    // pre-API 17 builds
                    // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4
                    if ((int)Build.VERSION.SdkInt < 17)
                    {
                        td.Callback = _drawableCallback;
                    }
                    else
                    {
                        ActionBar.SetBackgroundDrawable(td);
                    }

                    td.StartTransition(200);
                }

                _oldBackground = ld;

                // http://stackoverflow.com/questions/11002691/actionbar-setbackgrounddrawable-nulling-background-from-thread-handler
                ActionBar.SetDisplayShowTitleEnabled(false);
                ActionBar.SetDisplayShowTitleEnabled(true);
            }

            _currentColor = newColor;
        }
 public virtual void ChangeBackground()
 {
     if (checkbox.check)
     {
         SetBackgroundResource(Resource.Drawable.background_checkbox_check);
         LayerDrawable    layer = (LayerDrawable)Background;
         GradientDrawable shape = (GradientDrawable)layer.FindDrawableByLayerId(Resource.Id.shape_bacground);
         shape.SetColor(checkbox.backgroundColor);
     }
     else
     {
         SetBackgroundResource(Resource.Drawable.background_checkbox_uncheck);
     }
 }
예제 #3
0
 public virtual void ChangeBackground()
 {
     if (slider.val != slider.min)
     {
         SetBackgroundResource(Resource.Drawable.background_checkbox);
         LayerDrawable    layer = (LayerDrawable)Background;
         GradientDrawable shape = (GradientDrawable)layer.FindDrawableByLayerId(Resource.Id.shape_bacground);
         shape.SetColor(slider.backgroundColor);
     }
     else
     {
         SetBackgroundResource(Resource.Drawable.background_switch_ball_uncheck);
     }
 }
예제 #4
0
        public static LayerDrawable CircularIcon(Context ctx, int iconResId, ColorStateList iconColorList, ColorStateList backgroundColorList, int iconPadding = 10, int intrinsicSize = 100)
        {
            var icon = ResourcesCompat.GetDrawable(ctx.Resources, iconResId, null);

            icon?.SetTintList(iconColorList);
            var backgroundDrawable = Circle();

            backgroundDrawable?.SetTintList(backgroundColorList);
            var drw = new LayerDrawable(new Drawable[] { backgroundDrawable, icon });

            drw.SetLayerSize(0, intrinsicSize, intrinsicSize);
            drw.SetLayerInset(1, iconPadding, iconPadding, iconPadding, iconPadding);
            return(drw);
        }
예제 #5
0
        void DrawLine(CustomEntry entry)
        {
            // Background drawable
            GradientDrawable backgroundDrawable = new GradientDrawable();

            backgroundDrawable.SetShape(ShapeType.Rectangle);
            backgroundDrawable.SetColor(Color.Transparent.ToAndroid());

            // Bottom line normal
            GradientDrawable lineNormalDrawable = new GradientDrawable();

            lineNormalDrawable.SetShape(ShapeType.Rectangle);
            lineNormalDrawable.SetColor(entry.BorderColor.ToAndroid());
            lineNormalDrawable.SetSize((int)Element.Width, (int)DpToPixels(Context, 1));

            // Creates layer to contain background drawable and bottom line drawable
            int verticalPadding   = (int)DpToPixels(Context, 10);
            int horizontalPadding = (int)DpToPixels(Context, 5);

            Drawable[]    drawables   = new Drawable[] { backgroundDrawable, lineNormalDrawable };
            LayerDrawable normalLayer = new LayerDrawable(drawables);

            normalLayer.SetPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
            normalLayer.SetLayerInset(1, horizontalPadding, 0, horizontalPadding, (int)DpToPixels(Context, 8));
            normalLayer.SetLayerGravity(1, Android.Views.GravityFlags.Bottom);

            // Creates focused bottom line drawable
            GradientDrawable lineFocusedDrawable = new GradientDrawable();

            lineFocusedDrawable.SetShape(ShapeType.Rectangle);
            lineFocusedDrawable.SetColor(entry.FocusedBorderColor.ToAndroid());
            lineFocusedDrawable.SetSize((int)Element.Width, (int)DpToPixels(Context, 2));

            // Creates layer to contain background and focus drawable layers
            drawables = new Drawable[] { backgroundDrawable, lineFocusedDrawable };
            LayerDrawable focusLayer = new LayerDrawable(drawables);

            focusLayer.SetPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
            focusLayer.SetLayerInset(1, horizontalPadding, 0, horizontalPadding, (int)DpToPixels(Context, 8));
            focusLayer.SetLayerGravity(1, Android.Views.GravityFlags.Bottom);

            // Creates drawable state list
            StateListDrawable state = new StateListDrawable();

            state.AddState(new int[] { Android.Resource.Attribute.StateFocused }, focusLayer);
            state.AddState(new int[] { }, normalLayer);

            Control.SetBackground(state);
        }
예제 #6
0
        // Max of 2 characters
        public static void SetBadgeText(Context context, IMenuItem item, string text, Color backgroundColor, Color textColor)
        {
            if (item.Icon == null)
            {
                return;
            }

            BadgeDrawable badge = null;
            Drawable      icon  = item.Icon;


            if (item.Icon is LayerDrawable)
            {
                LayerDrawable lDrawable = item.Icon as LayerDrawable;

                if (string.IsNullOrEmpty(text) || text == "0")
                {
                    icon = lDrawable.GetDrawable(0);
                    lDrawable.Dispose();
                }
                else
                {
                    for (var i = 0; i < lDrawable.NumberOfLayers; i++)
                    {
                        if (lDrawable.GetDrawable(i) is BadgeDrawable)
                        {
                            badge = lDrawable.GetDrawable(i) as BadgeDrawable;
                            break;
                        }
                    }

                    if (badge == null)
                    {
                        badge = new BadgeDrawable(context, backgroundColor, textColor);
                        icon  = new LayerDrawable(new Drawable[] { item.Icon, badge });
                    }
                }
            }
            else
            {
                badge = new BadgeDrawable(context, backgroundColor, textColor);
                icon  = new LayerDrawable(new Drawable[] { item.Icon, badge });
            }

            badge?.SetBadgeText(text);

            item.SetIcon(icon);
            icon.Dispose();
        }
예제 #7
0
        public LayerDrawable AddPickerStyles(string imagePath)
        {
            ShapeDrawable border = new ShapeDrawable();

            //border.Paint.Color = Android.Graphics.Color.Gray;
            //border.SetPadding(10, 10, 10, 10);
            //border.Paint.SetStyle(Paint.Style.Stroke);

            Drawable[]    layers        = { GetDrawable(imagePath) };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            layerDrawable.SetLayerInset(0, 0, (int)jPicker.Padding.Top, 10, (int)jPicker.Padding.Bottom);

            return(layerDrawable);
        }
예제 #8
0
        private LayerDrawable GetLayeredBg()
        {
            var border = new ShapeDrawable();

            border.Paint.Color = global::Android.Graphics.Color.Argb(175, 255, 255, 255);
            border.SetPadding(0, 0, -6, 0);
            border.Paint.SetStyle(Paint.Style.Stroke);

            Drawable[]    layers        = { border, Context.GetDrawable("downarrow") };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            layerDrawable.SetLayerInset(0, 0, 0, 0, 0);

            return(layerDrawable);
        }
예제 #9
0
        private LayerDrawable makeClusterBackground()
        {
            Android.Graphics.Color color = Android.Graphics.Color.ParseColor("#80ffffff");

            mColoredCircleBackground = new ShapeDrawable(new OvalShape());
            ShapeDrawable outline = new ShapeDrawable(new OvalShape());

            /*		outline.Paint.Color = 0x80ffffff;  Transparent white.  */
            outline.Paint.Color = Android.Graphics.Color.ParseColor("#80ffffff");
            LayerDrawable background  = new LayerDrawable(new Drawable[] { outline, mColoredCircleBackground });
            int           strokeWidth = (int)(mDensity * 3);

            background.SetLayerInset(1, strokeWidth, strokeWidth, strokeWidth, strokeWidth);
            return(background);
        }
        public LayerDrawable AddPickerStyles(string imagePath)
        {
            ShapeDrawable border = new ShapeDrawable();

            border.Paint.Color = Android.Graphics.Color.Transparent;
            border.SetPadding(10, 10, 0, 10);
            border.Paint.SetStyle(Paint.Style.Stroke);

            Drawable[]    layers        = { border, GetDrawable(imagePath) };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            layerDrawable.SetLayerInset(0, 0, 0, 0, 0);

            return(layerDrawable);
        }
예제 #11
0
        public static void UpdateBackground(Border border, Android.Views.View view)
        {
            var strokeThickness = border.StrokeThickness;
            var context         = view.Context;

            // create stroke drawable
            GradientDrawable strokeDrawable = null;

            // if thickness exists, set stroke drawable stroke and radius
            if (strokeThickness.HorizontalThickness + strokeThickness.VerticalThickness > 0)
            {
                strokeDrawable = new GradientDrawable();
                strokeDrawable.SetColor(border.BackgroundColor.ToAndroid());

                // choose thickest margin
                // the content is padded so it will look like the margin is with the given thickness
                strokeDrawable.SetStroke((int)context.ToPixels(strokeThickness.ThickestSide()), border.Stroke.ToAndroid());
                strokeDrawable.SetCornerRadius((float)border.CornerRadius);
            }

            // create background drawable
            var backgroundDrawable = new GradientDrawable();

            // set background drawable color based on Border's background color
            backgroundDrawable.SetColor(border.BackgroundColor.ToAndroid());
            backgroundDrawable.SetCornerRadius((float)border.CornerRadius);

            if (strokeDrawable != null)
            {
                // if stroke drawable exists, create a layer drawable containing both stroke and background drawables
                var ld = new LayerDrawable(new Drawable[] { strokeDrawable, backgroundDrawable });
                ld.SetLayerInset(1, (int)context.ToPixels(strokeThickness.Left), (int)context.ToPixels(strokeThickness.Top), (int)context.ToPixels(strokeThickness.Right), (int)context.ToPixels(strokeThickness.Bottom));
                //view.SetBackgroundDrawable(ld);
                view.Background = ld;
            }
            else
            {
                //view.SetBackgroundDrawable(backgroundDrawable);
                view.Background = backgroundDrawable;
            }

            // set Android.View's padding to take into account the stroke thickiness
            view.SetPadding(
                (int)context.ToPixels(strokeThickness.Left + border.Padding.Left),
                (int)context.ToPixels(strokeThickness.Top + border.Padding.Top),
                (int)context.ToPixels(strokeThickness.Right + border.Padding.Right),
                (int)context.ToPixels(strokeThickness.Bottom + border.Padding.Bottom));
        }
예제 #12
0
        protected override void OnElementChanged(ElementChangedEventArgs <Entry> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement == null)
            {
                var nativeEditText = (global::Android.Widget.EditText)Control;
                var customEntry    = (CustomEntry)Element;

                GradientDrawable border = new GradientDrawable();
                border.SetStroke(1, customEntry.BorderColor.ToAndroid());
                Drawable[]    layers        = { border };
                LayerDrawable layerDrawable = new LayerDrawable(layers);
                layerDrawable.SetLayerInset(0, -2, -2, -2, 1);
                nativeEditText.Background = layerDrawable;
            }
        }
예제 #13
0
        protected async Task ChangeBackgroundImageAsync()
        {
            if (!(Element is CalendarButton element) || element.BackgroundImage == null)
            {
                return;
            }

            var d     = new List <Drawable>();
            var image = await GetBitmap(element.BackgroundImage);

            d.Add(new BitmapDrawable(image));
            var layer = new LayerDrawable(d.ToArray());

            layer.SetLayerInset(d.Count - 1, 0, 0, 0, 0);
            Control?.SetBackground(layer);
        }
예제 #14
0
        protected void ChangeBackgroundPattern()
        {
            var element = Element as CalendarButton;

            if (element == null || element.BackgroundPattern == null || Control.Width == 0)
            {
                return;
            }

            var d = new List <Drawable>();

            for (var i = 0; i < element.BackgroundPattern.Pattern.Count; i++)
            {
                var bp = element.BackgroundPattern.Pattern[i];
                if (!string.IsNullOrEmpty(bp.Text))
                {
                    d.Add(new TextDrawable(bp.Color.ToAndroid())
                    {
                        Pattern = bp
                    });
                }
                else
                {
                    d.Add(new ColorDrawable(bp.Color.ToAndroid()));
                }
            }
            var drawable = new GradientDrawable();

            drawable.SetShape(ShapeType.Rectangle);
            var borderWidth = (int)Math.Ceiling(Element.BorderWidth);

            drawable.SetStroke(borderWidth > 0 ? borderWidth + 1 : borderWidth, Element.BorderColor.ToAndroid());
            drawable.SetColor(Android.Graphics.Color.Transparent);
            d.Add(drawable);
            var layer = new LayerDrawable(d.ToArray());

            for (var i = 0; i < element.BackgroundPattern.Pattern.Count; i++)
            {
                var l = (int)Math.Ceiling(Control.Width * element.BackgroundPattern.GetLeft(i));
                var t = (int)Math.Ceiling(Control.Height * element.BackgroundPattern.GetTop(i));
                var r = (int)Math.Ceiling(Control.Width * (1 - element.BackgroundPattern.Pattern[i].WidthPercent)) - l;
                var b = (int)Math.Ceiling(Control.Height * (1 - element.BackgroundPattern.Pattern[i].HightPercent)) - t;
                layer.SetLayerInset(i, l, t, r, b);
            }
            layer.SetLayerInset(d.Count - 1, 0, 0, 0, 0);
            Control.SetBackground(layer);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.ProviderProfile);
            RatingBar     ratingBar = FindViewById <RatingBar>(Resource.Id.ratingBar);
            ImageButton   btnback   = FindViewById <ImageButton>(Resource.Id.btnback);
            LayerDrawable stars     = (LayerDrawable)ratingBar.ProgressDrawable;

            stars.GetDrawable(2).SetColorFilter(Color.Yellow, PorterDuff.Mode.SrcAtop);

            productlayot                = FindViewById <LinearLayout>(Resource.Id.productlayout);
            reviewconsumerlayout        = FindViewById <LinearLayout>(Resource.Id.reviewconsumerlayout);
            productlayot.Click         += Productlayot_Click;
            reviewconsumerlayout.Click += Reviewconsumerlayout_Click;
            btnback.Click              += Btnback_Click;
            // Create your application here
        }
        void DrawLine(IMenuItem item)
        {
            int lineWidth               = 8;
            int itemHeight              = bottomNavi.Height;
            var rest                    = System.Convert.ToInt32("-" + itemHeight);
            int itemWidth               = (bottomNavi.Width / Element.Children.Count);
            int leftOffset              = item.ItemId * itemWidth;
            int rightOffset             = itemWidth * (Element.Children.Count - (item.ItemId + 1));
            GradientDrawable bottomLine = new GradientDrawable();

            bottomLine.SetShape(ShapeType.Line);
            bottomLine.SetStroke(lineWidth, tab.SelectedTabColor.ToAndroid());
            var layerDrawable = new LayerDrawable(new Drawable[] { bottomLine });

            layerDrawable.SetLayerInset(0, leftOffset, rest, rightOffset, 0);
            bottomNavi.SetBackground(layerDrawable);
        }
        bool IViewHierarchyHandler.TryGetHighlightedView(double x, double y, bool clear, out IInspectView chosenView)
        {
            chosenView = null;

            if (highlightedView != null)
            {
                highlightedView.SetBackgroundDrawable(highlightedViewOriginalBackground);
                highlightedView = null;
                highlightedViewOriginalBackground = null;
            }

            var view = GetViewAt(GetTopActivity(), x, y);

            if (view == null)
            {
                return(false);
            }

            if (!clear)
            {
                highlightedView = view;
                highlightedViewOriginalBackground = this.highlightedView.Background;

                var gd = new GradientDrawable();
                gd.SetColor(AG.Color.Red.ToArgb());
                gd.SetAlpha(255 / 2);
                //gd.SetCornerRadius (5);
                //gd.SetStroke (1, AG.Color.Red);

                Drawable highlightedBackground;
                if (highlightedViewOriginalBackground == null)
                {
                    highlightedBackground = gd;
                }
                else
                {
                    highlightedBackground =
                        new LayerDrawable(new [] { highlightedViewOriginalBackground, gd });
                }

                highlightedView.SetBackgroundDrawable(highlightedBackground);
            }

            chosenView = new AndroidInspectView(view, withSubviews: false);
            return(true);
        }
예제 #18
0
        public void SetStars()
        {
            ratingBar = new RatingBar(this.Context, null, element.IsSmallStyle ? Android.Resource.Attribute.RatingBarStyleSmall
                           : Android.Resource.Attribute.RatingBarStyle)
            {
                StepSize = 1.0f,
                NumStars = element.MaxStars,
                Rating   = element.Rating,
            };

            RegisterEvents(element.IsReadonly);

            LayerDrawable drawable = (LayerDrawable)ratingBar.ProgressDrawable;

            SetDefaultColor(drawable);
            SetFillColor(drawable);
            SetNativeControl(ratingBar);
        }
예제 #19
0
        private Drawable CreateUserIconDrawable()
        {
            int           dp16       = PixelSizeConverter.DpToPx(16);
            int           dp12       = PixelSizeConverter.DpToPx(12);
            int           dp4        = PixelSizeConverter.DpToPx(4);
            var           fillColor  = new Color(ResourcesCompat.GetColor(_layout.Resources, Resource.Color.user_location, null));
            var           ringColor  = new Color(ResourcesCompat.GetColor(_layout.Resources, Resource.Color.user_location_stroke, null));
            var           pointColor = new Color(ResourcesCompat.GetColor(_layout.Resources, Resource.Color.user_location_center, null));
            LayerDrawable drw        = new LayerDrawable(new Drawable[] { CircleDrawable(ringColor, dp16), CircleDrawable(fillColor, dp12), CircleDrawable(pointColor, dp4) });

            drw.SetLayerSize(0, dp16, dp16);
            drw.SetLayerSize(1, dp12, dp12);
            drw.SetLayerSize(2, dp4, dp4);
            drw.SetLayerGravity(0, GravityFlags.Center);
            drw.SetLayerGravity(1, GravityFlags.Center);
            drw.SetLayerGravity(2, GravityFlags.Center);
            return(drw);
        }
예제 #20
0
        public static void SetPickerStyles(EditText control)
        {
            if (control == null)
            {
                return;
            }

            GradientDrawable gd = new GradientDrawable();

            gd.SetColor(ColorStateList.ValueOf(Android.Graphics.Color.White));
            gd.SetCornerRadius(50);

            Drawable[]    layers        = { gd, GetDrawable(control) };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            control.Background = layerDrawable;
            control.Gravity    = Android.Views.GravityFlags.Center;
        }
예제 #21
0
        public void OnDetached()
        {
            if (notSupported)
            {
                return;
            }

            _thumb.Dispose();
            _progress.Dispose();

            _thumb                 = null;
            _progress              = null;
            _orgProgress           = null;
            _orgThumb              = null;
            _orgProgressBackground = null;
            _seekbar               = null;
            _element               = null;
        }
        private Drawable GetDisabledThumbDrawable()
        {
            if (MaterialUI)
            {
                return(GetMaterialUiThumbDrawable(DefaultColor));
            }
            else
            {
                var outerCircle = Circle(DefaultGrayColor);
                var innerCircle = Circle(DefaultDarkBlueColor);

                LayerDrawable ld = new LayerDrawable(new Drawable[] { outerCircle, innerCircle });
                ld.SetLayerInset(0, 8, 8, 8, 8);
                ld.SetLayerInset(1, 28, 28, 28, 28);
                ld.SetBounds(0, 0, 64, 64);
                return(ld);
            }
        }
        private Drawable GetThumbDrawable()
        {
            if (MaterialUI)
            {
                return(GetMaterialUiThumbDrawable(ActiveColor));
            }
            else
            {
                var           outerCircle = Circle(DefaultLightBlueColor);
                var           innerCircle = Circle(DefaultDarkBlueColor);
                LayerDrawable ld          = new LayerDrawable(new Drawable[] { outerCircle, innerCircle });

                ld.SetLayerInset(0, 4, 4, 4, 4);
                ld.SetLayerInset(1, 23, 23, 23, 23);
                ld.SetBounds(0, 0, 64, 64);
                return(ld);
            }
        }
        //protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        //{
        //    try
        //    {
        //        var nativeCtrl = Control;
        //        var formsElement = Element;
        //        if (nativeCtrl == null || formsElement == null)
        //        {
        //            base.DispatchDraw(canvas);
        //            return;
        //        }

        //        //convert from logical to native metrics if need be
        //        var shadowDistanceX = 10f;
        //        var shadowDistanceY = 10f;
        //        var shadowRadius = 5f;
        //        var shadowOpacity = .5f;
        //        var shadowColor = Color.Black;
        //        var cornerRadius = 2.0f;

        //        var bounds = formsElement.Bounds;

        //        var left = shadowDistanceX;
        //        var top = shadowDistanceY;
        //        var right = Width + shadowDistanceX;
        //        var bottom = Height + shadowDistanceY;

        //        var rect = new Android.Graphics.RectF(left, top, right, bottom);

        //        canvas.Save();
        //        using (var paint = new Android.Graphics.Paint { AntiAlias = true })
        //        {
        //            paint.SetStyle(Android.Graphics.Paint.Style.Fill);

        //            var nativeShadowColor = shadowColor.MultiplyAlpha(shadowOpacity * 0.75f).ToAndroid();
        //            paint.Color = nativeShadowColor;

        //            var gradient = new Android.Graphics.RadialGradient(
        //                0.5f, 0.5f,
        //                shadowRadius,
        //                shadowColor.ToAndroid(),
        //                nativeShadowColor,
        //                Android.Graphics.Shader.TileMode.Clamp
        //            );
        //            paint.SetShader(gradient);

        //            //convert from logical to native metrics if need be
        //            var nativeRadius = cornerRadius;
        //            canvas.DrawRoundRect(rect, nativeRadius, nativeRadius, paint);

        //            var clipPath = new Android.Graphics.Path();
        //            clipPath.AddRoundRect(new Android.Graphics.RectF(0f, 0f, Width, Height), nativeRadius, nativeRadius, Android.Graphics.Path.Direction.Cw);
        //            canvas.ClipPath(clipPath);
        //        }
        //        canvas.Restore();
        //    }
        //    catch (Exception ex)
        //    {
        //        //log exception
        //    }

        //    base.DispatchDraw(canvas);
        //}



        public LayerDrawable AddPickerStyles()
        {
            var shape = new ShapeDrawable(new Android.Graphics.Drawables.Shapes.RectShape());

            shape.Paint.Color = Android.Graphics.Color.Transparent;
            shape.Paint.SetStyle(Paint.Style.Stroke);
            shape.SetPadding(30, 10, 20, 10);
            shape.Paint.StrokeWidth = 0;

            var gdBorderColor     = GetBorderDrawable(customControl.BorderWidth, customControl.BorderColor, customControl.RoundedCornerRadius);
            var gdBackgroundColor = GetBackgroundColorDrawable(customControl.RoundedCornerRadius, customControl.BackgroundColor);

            Drawable[]    layers        = { gdBackgroundColor, gdBorderColor, shape };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            layerDrawable.SetLayerInset(0, 0, 0, 0, 0);

            return(layerDrawable);
        }
예제 #25
0
        private LayerDrawable GetBorderDrawable(Xamarin.Forms.Color borderColor, Xamarin.Forms.Color backgroundColor, float borderWidth, int borderRadius, ImageSource imageSource)
        {
            GradientDrawable gd = new GradientDrawable();

            borderWidth     = borderWidth > 0 ? borderWidth : 0;
            borderRadius    = borderRadius > 0 ? borderRadius : 0;
            borderColor     = borderColor != Xamarin.Forms.Color.Default ? borderColor : Xamarin.Forms.Color.Transparent;
            backgroundColor = backgroundColor != Xamarin.Forms.Color.Default ? backgroundColor : Xamarin.Forms.Color.Transparent;

            gd.SetColor(ColorStateList.ValueOf(backgroundColor.ToAndroid()));
            gd.SetStroke((int)borderWidth, ColorStateList.ValueOf(borderColor.ToAndroid()));
            gd.SetCornerRadius((float)borderRadius);
            Drawable[]    layers        = { gd, GetImageDrawable(imageSource as FileImageSource) };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            layerDrawable.SetLayerInset(0, 0, 0, 0, 0);
            layerDrawable.SetLayerInset(1, 0, 0, 18, 0);
            return(layerDrawable);
        }
예제 #26
0
        //Adding line view
        void SetupBottomNavigationView(IMenuItem item)
        {
            int lineBottomOffset        = 8;
            int lineWidth               = 4;
            int itemHeight              = bottomNavigationView.Height - lineBottomOffset;
            int itemWidth               = (bottomNavigationView.Width / Element.Children.Count);
            int leftOffset              = item.ItemId * itemWidth;
            int rightOffset             = itemWidth * (Element.Children.Count - (item.ItemId + 1));
            GradientDrawable bottomLine = new GradientDrawable();

            bottomLine.SetShape(ShapeType.Line);
            bottomLine.SetStroke(lineWidth, Xamarin.Forms.Color.DarkGray.ToAndroid());

            var layerDrawable = new LayerDrawable(new Drawable[] { bottomLine });

            layerDrawable.SetLayerInset(0, leftOffset, itemHeight, rightOffset, 0);

            bottomNavigationView.SetBackground(layerDrawable);
        }
예제 #27
0
        private Drawable CreateDrawable(int color)
        {
            var ovalShape     = new OvalShape();
            var shapeDrawable = new ShapeDrawable(ovalShape);

            shapeDrawable.Paint.Color = new Color(color);
            if (hasShadow && !HasLollipopApi)
            {
                var shadowDrawable = ContextCompat.GetDrawable(Application.Context, size == FabSize.Normal ? Resource.Drawable.fab_shadow : Resource.Drawable.fab_shadow_mini);

                var layerDrawable = new LayerDrawable(new Drawable[] { shadowDrawable, shapeDrawable });
                layerDrawable.SetLayerInset(1, shadowSize, shadowSize, shadowSize, shadowSize);
                return(layerDrawable);
            }
            else
            {
                return(shapeDrawable);
            }
        }
예제 #28
0
        private void ApplyStyle()
        {
            var frame = Element as CustomFrame;

            var gradientDrawable = new GradientDrawable();

            gradientDrawable.SetCornerRadius(frame.CornerRadius);
            gradientDrawable.SetOrientation(GradientDrawable.Orientation.BottomTop);
            gradientDrawable.SetColors(new int[] { frame.EndColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb(),
                                                   frame.StartColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb() });
            if (frame.HasBorder)
            {
                gradientDrawable.SetStroke((int)frame.StrokeThickness, frame.OutlineColor.ToAndroid());
            }

            var ld = default(LayerDrawable);

            if (frame.HasShadow)
            {
                var shadow = new GradientDrawable();

                int[] colors1 = { frame.ShadowColor.MultiplyAlpha(frame.AlphaMultiplier).ToAndroid().ToArgb(),
                                  Color.Transparent.ToAndroid().ToArgb() };
                shadow.SetOrientation(GradientDrawable.Orientation.TopBottom);
                //shadow.SetColors(colors1);
                shadow.SetStroke((int)frame.StrokeThickness + 5, frame.ShadowColor.ToAndroid());
                shadow.SetCornerRadius(frame.CornerRadius);

                ld = new LayerDrawable(new Drawable[] { shadow, gradientDrawable });

                ld.SetLayerInset(0, 0, 0, 0, 0);
                ld.SetLayerInset(1, 0, 6, 0, 0);
            }
            else
            {
                ld = new LayerDrawable(new Drawable[] { gradientDrawable });
                ld.SetLayerInset(0, 0, 0, 0, 0);
            }

            Background = ld;
        }
예제 #29
0
        public static Drawable GenerateBackgroundWithShadow(RoundedCornerStackLayout control, Android.Views.View child, Android.Graphics.Color backgroundColor,
                                                            Android.Graphics.Color shadowColor,
                                                            int elevation,
                                                            GravityFlags shadowGravity)
        {
            var radii = GetRadii(control);

            int DY;

            switch (shadowGravity)
            {
            case GravityFlags.Center:
                DY = 0;
                break;

            case GravityFlags.Top:
                DY = -1 * elevation / 3;
                break;

            default:
            case GravityFlags.Bottom:
                DY = elevation / 3;
                break;
            }

            var shapeDrawable = new ShapeDrawable();

            shapeDrawable.Paint.Color = backgroundColor;
            shapeDrawable.Paint.SetShadowLayer(elevation, 0, DY, shadowColor);

            child.SetLayerType(LayerType.Software, shapeDrawable.Paint);

            shapeDrawable.Shape = new RoundRectShape(radii, null, null);

            var drawable = new LayerDrawable(new Drawable[] { shapeDrawable });

            drawable.SetLayerInset(0, elevation, elevation, elevation, elevation);

            child.Background = drawable;
            return(drawable);
        }
예제 #30
0
        public LayerDrawable AddPickerStyles(string iconPath, int iconDistance)
        {
            //ShapeDrawable border = new ShapeDrawable();
            //border.Paint.Color = Android.Graphics.Color.Gray;
            //border.SetPadding(10, 10, 10, 10);
            //border.Paint.SetStyle(Paint.Style.Stroke);
            //
            //Drawable[] layers = { border, GetDrawable(imagePath) };
            //LayerDrawable layerDrawable = new LayerDrawable(layers);
            //layerDrawable.SetLayerInset(0, 0, 0, 0, 0);
            //
            //return layerDrawable;

            GradientDrawable grand = new GradientDrawable();

            Android.Graphics.Color catalystDarkGrey = Android.Graphics.Color.ParseColor("#605e5e");
            grand.SetStroke(3, catalystDarkGrey);

            //ContextCompat.GetDrawable(Context, Resource.Drawable.edittextbottombar)

            Drawable[]    layers        = { grand, GetDrawable(iconPath) };
            LayerDrawable layerDrawable = new LayerDrawable(layers);

            //layerDrawable.SetLayerInset(1, 10, 10, 10, 10);


            if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
            {
                layerDrawable.SetLayerInsetRight(1, iconDistance);
            }
            else
            {
                layerDrawable.SetLayerInset(1, 0, 0, iconDistance, 0);
            }
            //layerDrawable.SetLayerInsetRight(1, iconDistance);

            //layerDrawable.SetLayerInsetRight(0, 100);


            return(layerDrawable);
        }