From b3ae8bfb6f720990703ab543ccaee53d01571040 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Oct 2013 09:59:27 -0700 Subject: [PATCH] Try the passed in string without an extension on Android for resource loading --- Splat/Android/Bitmaps.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Splat/Android/Bitmaps.cs b/Splat/Android/Bitmaps.cs index 3fa707370..93a06def5 100644 --- a/Splat/Android/Bitmaps.cs +++ b/Splat/Android/Bitmaps.cs @@ -9,6 +9,8 @@ using System.Collections.Generic; using System.Linq; +using Path = System.IO.Path; + namespace Splat { public class PlatformBitmapLoader : IBitmapLoader @@ -55,6 +57,13 @@ public Task LoadFromResource(string source, float? desiredWidth, float? return Task.Run(() => (IBitmap)new DrawableBitmap(res.GetDrawable(drawableList[source]))); } + // NB: On iOS, you have to pass the extension, but on Android it's + // stripped - try stripping the extension to see if there's a Drawable. + var key = Path.GetFileNameWithoutExtension(source); + if (drawableList.ContainsKey(key)) { + return Task.Run(() => (IBitmap)new DrawableBitmap(res.GetDrawable(drawableList[key]))); + } + throw new ArgumentException("Either pass in an integer ID cast to a string, or the name of a drawable resource"); }