Как я это сделал.
Создан пользовательский рендер для просмотра. Со свойствами для основного цвета, темной тени и светлой тени -
public class NeumorphicCircleBackground : View
{
public static readonly BindableProperty LightColorProperty =
BindableProperty.Create("LightColor", typeof(Color), typeof(NeumorphicCircleBackground), null);
public Color LightColor
{
get { return (Color)GetValue(LightColorProperty); }
set { SetValue(LightColorProperty, value); }
}
public static readonly BindableProperty MainColorProperty =
BindableProperty.Create("MainColor", typeof(Color), typeof(NeumorphicCircleBackground), null);
public Color MainColor
{
get { return (Color)GetValue(MainColorProperty); }
set { SetValue(MainColorProperty, value); }
}
public static readonly BindableProperty DarkColorProperty =
BindableProperty.Create("DarkColor", typeof(Color), typeof(NeumorphicCircleBackground), null);
public Color DarkColor
{
get { return (Color)GetValue(DarkColorProperty); }
set { SetValue(DarkColorProperty, value); }
}
}
и представлением Android -
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
var h = canvas.Height;
var w = canvas.Width;
var size = Math.Min(h, w);
float a = 0.1f * size;
float b = 0.6f * size;
float x0 = (w - size) / 2;
float y0 = 0f;
RectF ovalLight = new RectF();
RectF ovalMain = new RectF();
RectF ovalDark = new RectF();
ovalLight.Set(x0, y0, x0 + b, y0 + b);
ovalMain.Set(x0 + a, y0 + a, x0 + a + b, y0 + a + b);
ovalDark.Set(x0 + 2 * a, y0 + 2 * a, x0 + 2 * a + b, y0 + 2 * a + b);
var r = b / 2;
var xl = x0 + b / 2;
var yl = y0 + b / 2;
var xd = x0 + 2 * a + b / 2;
var yd = y0 + 2 * a + b / 2;
var xm = x0 + a + b / 2;
var ym = y0 + a + b / 2;
var lightGradient = GetRadialPaint(xl, yl, r, _lightColor);
var darkGradient = GetRadialPaint(xd, yd, r, _darkColor);
var mainGradient = new Paint(PaintFlags.AntiAlias) { Color = _mainColor };
if (_isCircle)
{
DrawCircle(canvas, xl, yl, r, lightGradient);
DrawCircle(canvas, xd, yd, r, darkGradient);
DrawCircle(canvas, xm, ym, r, mainGradient);
}
else
{
DrawRoundedRectangle(canvas, ovalLight, 50f, 50f, lightGradient);
DrawRoundedRectangle(canvas, ovalDark, 50f, 50f, darkGradient);
DrawRoundedRectangle(canvas, ovalMain, 50f, 50f, mainGradient);
}
}
я добавил дополнительные свойства, чтобы сделать его обобщенным c Закругленный угол Прямоугольник, а также идеальный круг. Вы можете изменить его так, как хотите.