summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Platform.Android/Forms.cs47
1 files changed, 34 insertions, 13 deletions
diff --git a/Xamarin.Forms.Platform.Android/Forms.cs b/Xamarin.Forms.Platform.Android/Forms.cs
index 62e07f22..a2a063c9 100644
--- a/Xamarin.Forms.Platform.Android/Forms.cs
+++ b/Xamarin.Forms.Platform.Android/Forms.cs
@@ -96,19 +96,7 @@ namespace Xamarin.Forms
ResourceManager.Init(resourceAssembly);
- // Detect if legacy device and use appropriate accent color
- // Hardcoded because could not get color from the theme drawable
- var sdkVersion = (int)Build.VERSION.SdkInt;
- if (sdkVersion <= 10)
- {
- // legacy theme button pressed color
- Color.Accent = Color.FromHex("#fffeaa0c");
- }
- else
- {
- // Holo dark light blue
- Color.Accent = Color.FromHex("#ff33b5e5");
- }
+ Color.Accent = GetAccentColor();
if (!IsInitialized)
Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c)));
@@ -148,6 +136,39 @@ namespace Xamarin.Forms
IsInitialized = true;
}
+ static Color GetAccentColor()
+ {
+ Color rc;
+ using (var value = new TypedValue())
+ {
+ if (Context.Theme.ResolveAttribute(global::Android.Resource.Attribute.ColorAccent, value, true)) // 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)Build.VERSION.SdkInt;
+ if (sdkVersion <= 10)
+ {
+ // legacy theme button pressed color
+ rc = Color.FromHex("#fffeaa0c");
+ }
+ else
+ {
+ // Holo dark light blue
+ rc = Color.FromHex("#ff33b5e5");
+ }
+ }
+ }
+ return rc;
+ }
+
class AndroidDeviceInfo : DeviceInfo
{
readonly IDeviceInfoProvider _formsActivity;