private Drawable CreateBackgroundButton() { var layer1 = BackgroundExtension.CreateBackgroundGradient(button.StartColor.ToAndroid(), button.EndColor.ToAndroid(), button.CenterColor.ToAndroid(), button.CornerRadius, button.Angle.ToAndroid()); var layer1Disabled = BackgroundExtension.CreateBackgroundGradient(Android.Graphics.Color.Gray, Android.Graphics.Color.Gray, Android.Graphics.Color.Gray, button.CornerRadius, button.Angle.ToAndroid()); var layer2Temp = BackgroundExtension.CreateBackgroundGradient(backgroundColor.ToAndroid(), backgroundColor.ToAndroid(), backgroundColor.ToAndroid(), button.CornerRadius, button.Angle.ToAndroid()); int borderWidth = (int)button.BorderWidth; var layer2 = new InsetDrawable(layer2Temp, borderWidth, borderWidth, borderWidth, borderWidth); Drawable[] drawables = new Drawable[] { layer1, layer2 }; Drawable[] drawablesDisabled = new Drawable[] { layer1Disabled, layer2 }; LayerDrawable layer = new LayerDrawable(drawables); LayerDrawable layerDisabled = new LayerDrawable(drawablesDisabled); 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); }
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())); }
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); }