зеркало из https://github.com/DeGsoft/maui-linux.git
42 строки
1.3 KiB
C#
42 строки
1.3 KiB
C#
using Android.Content.Res;
|
|
using AColor = Android.Graphics.Color;
|
|
|
|
namespace Xamarin.Forms.Platform.Android
|
|
{
|
|
public static class ColorExtensions
|
|
{
|
|
static readonly int[][] ColorStates = { new[] { global::Android.Resource.Attribute.StateEnabled }, new[] { -global::Android.Resource.Attribute.StateEnabled } };
|
|
|
|
public static AColor ToAndroid(this Color self)
|
|
{
|
|
return new AColor((byte)(byte.MaxValue * self.R), (byte)(byte.MaxValue * self.G), (byte)(byte.MaxValue * self.B), (byte)(byte.MaxValue * self.A));
|
|
}
|
|
|
|
public static AColor ToAndroid(this Color self, int defaultColorResourceId)
|
|
{
|
|
if (self == Color.Default)
|
|
{
|
|
using (Resources resources = Resources.System)
|
|
#pragma warning disable 618
|
|
return resources.GetColor(defaultColorResourceId);
|
|
#pragma warning restore 618
|
|
}
|
|
|
|
return ToAndroid(self);
|
|
}
|
|
|
|
public static AColor ToAndroid(this Color self, Color defaultColor)
|
|
{
|
|
if (self == Color.Default)
|
|
return defaultColor.ToAndroid();
|
|
|
|
return ToAndroid(self);
|
|
}
|
|
|
|
public static ColorStateList ToAndroidPreserveDisabled(this Color color, ColorStateList defaults)
|
|
{
|
|
int disabled = defaults.GetColorForState(ColorStates[1], color.ToAndroid());
|
|
return new ColorStateList(ColorStates, new[] { color.ToAndroid().ToArgb(), disabled });
|
|
}
|
|
}
|
|
} |