diff options
author | Michael Rumpler <michael@mrumpler.at> | 2016-08-02 22:54:40 +0200 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-08-02 13:54:40 -0700 |
commit | 08e282350cb3f1c2345125682f14934111af2f9c (patch) | |
tree | fe6b0877ddec1561efc0d1427b5440645233dde1 /Xamarin.Forms.Platform.Android/Forms.cs | |
parent | 89199205e48fe3fdf4336fe7e0f8af7dc0b662de (diff) | |
download | xamarin-forms-08e282350cb3f1c2345125682f14934111af2f9c.tar.gz xamarin-forms-08e282350cb3f1c2345125682f14934111af2f9c.tar.bz2 xamarin-forms-08e282350cb3f1c2345125682f14934111af2f9c.zip |
[Android] Color.Accent is hardcoded (#270)
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Forms.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Forms.cs | 47 |
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; |