summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Forms.cs
diff options
context:
space:
mode:
authorMichael Rumpler <michael@mrumpler.at>2016-08-02 20:54:40 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-08-02 20:54:40 (GMT)
commit08e282350cb3f1c2345125682f14934111af2f9c (patch)
treefe6b0877ddec1561efc0d1427b5440645233dde1 /Xamarin.Forms.Platform.Android/Forms.cs
parent89199205e48fe3fdf4336fe7e0f8af7dc0b662de (diff)
downloadxamarin-forms-08e282350cb3f1c2345125682f14934111af2f9c.zip
xamarin-forms-08e282350cb3f1c2345125682f14934111af2f9c.tar.gz
xamarin-forms-08e282350cb3f1c2345125682f14934111af2f9c.tar.bz2
[Android] Color.Accent is hardcoded (#270)
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Forms.cs')
-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 62e07f2..a2a063c 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;