コード例 #1
0
        private Drawable CreateBackgroundFrame()
        {
            List <Drawable> drawables = new List <Drawable>();
            var             layer1    = BackgroundExtension.CreateBackgroundGradient(grid.StartColor.ToAndroid(),
                                                                                     grid.EndColor.ToAndroid(),
                                                                                     grid.CenterColor.ToAndroid(), grid.CornerRadius, grid.Angle.ToAndroid());

            drawables.Add(layer1);
            if (grid.Image != null && !string.IsNullOrEmpty(grid.Image.File))
            {
                var bitmapDrawable = BackgroundExtension.CreateBackgroundBitmap(grid.Image.File, (int)grid.Height,
                                                                                (int)grid.Width, grid.CornerRadius);
                if (bitmapDrawable != null)
                {
                    drawables.Add(bitmapDrawable);
                }
            }
            return(new LayerDrawable(drawables.ToArray()));
        }
コード例 #2
0
        Drawable CreateBackgroundForButton(bool renderImage = true)
        {
            List <Drawable> drawables         = new List <Drawable>();
            List <Drawable> drawablesDisabled = new List <Drawable>();

            drawables.Add(BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                       button.EndColor.ToAndroid(),
                                                                       button.CenterColor.ToAndroid(),
                                                                       button.CornerRadius,
                                                                       button.Angle.ToAndroid()));
            drawablesDisabled.Add(BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(),
                                                                               button.EndColor.ToAndroid(),
                                                                               button.CenterColor.ToAndroid(),
                                                                               button.CornerRadius,
                                                                               button.Angle.ToAndroid()));
            if (button.Image != null && !string.IsNullOrEmpty(button.Image.File) && renderImage)
            {
                var bitmapDrawable = BackgroundExtension.CreateBackgroundBitmap(button.Image.File, (int)button.HeightRequest,
                                                                                (int)button.WidthRequest, button.CornerRadius);
                if (bitmapDrawable != null)
                {
                    drawables.Add(bitmapDrawable);
                    drawablesDisabled.Add(bitmapDrawable);
                }
            }
            Drawable layer         = new LayerDrawable(drawables.ToArray());
            Drawable layerDisabled = new LayerDrawable(drawablesDisabled.ToArray());

            layerDisabled.Mutate().Alpha = 80;
            var statesListDrawable       = new StateListDrawable();

            statesListDrawable.AddState(new int[] { -Android.Resource.Attribute.StateEnabled }, layerDisabled);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StatePressed }, layer);
            statesListDrawable.AddState(new int[] { Android.Resource.Attribute.StateEnabled }, layer);
            return(statesListDrawable);
        }