This commit is contained in:
Stephane Delcroix 2018-09-24 09:03:49 +02:00
Родитель ea42a07ffb 2268657174
Коммит d6bd40fc12
1 изменённых файлов: 37 добавлений и 26 удалений

Просмотреть файл

@ -59,15 +59,20 @@ namespace Xamarin.Forms.Platform.Android
if (colorToSet == Color.Default)
colorToSet = Element.BackgroundColor;
if (_backgroundDrawable == null)
_backgroundDrawable = new GradientDrawable();
if (_backgroundDrawable != null) {
if (colorToSet != Color.Default)
_backgroundDrawable.SetColor(colorToSet.ToAndroid());
else
_backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent));
if (colorToSet != Color.Default)
_backgroundDrawable.SetColor(colorToSet.ToAndroid());
else
_backgroundDrawable.SetColor(colorToSet.ToAndroid(Color.Transparent));
this.SetBackground(_backgroundDrawable);
this.SetBackground(_backgroundDrawable);
}
else {
if (colorToSet == Color.Default)
colorToSet = Element.BackgroundColor;
SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent));
}
}
protected override void Dispose(bool disposing)
@ -101,26 +106,32 @@ namespace Xamarin.Forms.Platform.Android
void UpdateCornerRadius()
{
var cornerRadius = Element.CornerRadius;
if (Background is GradientDrawable backgroundGradient)
{
var cornerRadii = new[]
{
(float)(cornerRadius.TopLeft),
(float)(cornerRadius.TopLeft),
(float)(cornerRadius.TopRight),
(float)(cornerRadius.TopRight),
(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomLeft),
(float)(cornerRadius.BottomLeft)
};
backgroundGradient.SetCornerRadii(cornerRadii);
if (cornerRadius == new CornerRadius(0d)) {
_backgroundDrawable?.Dispose();
_backgroundDrawable = null;
}
else {
this.SetBackground(_backgroundDrawable = new GradientDrawable());
if (Background is GradientDrawable backgroundGradient) {
var cornerRadii = new[] {
(float)(cornerRadius.TopLeft),
(float)(cornerRadius.TopLeft),
(float)(cornerRadius.TopRight),
(float)(cornerRadius.TopRight),
(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomRight),
(float)(cornerRadius.BottomLeft),
(float)(cornerRadius.BottomLeft)
};
backgroundGradient.SetCornerRadii(cornerRadii);
}
}
UpdateBackgroundColor();
}
}
}