static Color GetAccentColor(Context context) { Color rc; using (var value = new TypedValue()) { if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ColorAccent, value, true) && Forms.IsLollipopOrNewer) // Android 5.0+ { rc = Color.FromUint((uint)value.Data); } else if (context.Theme.ResolveAttribute(context.Resources.GetIdentifier("colorAccent", "attr", context.PackageName), value, true)) // < Android 5.0 { rc = Color.FromUint((uint)value.Data); } else // fallback to old code if nothing works (don't know if that ever happens) { // Detect if legacy device and use appropriate accent color // Hardcoded because could not get color from the theme drawable var sdkVersion = (int)SdkInt; if (sdkVersion <= 10) { // legacy theme button pressed color rc = Color.FromHex("#fffeaa0c"); } else { // Holo dark light blue rc = Color.FromHex("#ff33b5e5"); } } } return(rc); }
static Color GetButtonColor(Context context) { Color rc = ColorButtonNormalOverride; if (ColorButtonNormalOverride == Color.Default) { using (var value = new TypedValue()) { if (context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ColorButtonNormal, value, true) && Forms.IsLollipopOrNewer) // Android 5.0+ { rc = Color.FromUint((uint)value.Data); } else if (context.Theme.ResolveAttribute(context.Resources.GetIdentifier("colorButtonNormal", "attr", context.PackageName), value, true)) // < Android 5.0 { rc = Color.FromUint((uint)value.Data); } } } return(rc); }