Xamarin Forms, Android and images – things to remember
Join the DZone community and get the full member experience.Join For Free
If you are using Xamarin Forms for your next awesome cross-platform mobile app, there are things you need to remember when dealing with images for Android.
1. No folders
Even though you can group images into subfolders at root level for Windows Phone or under
Resources for iOS, all images have to be inside the
Drawable folder for Android. Images in folders are not used.
Images/picture.png still resolves on Android.
Which brings us to the obvious…
2. No duplicates
You cannot have two images with the same name in two different folders like
Because you cannot have two files with the same name in the same folder.
However, there are still problems with file names…
3. Invalid characters in file names
After reading point 2, you renamed your files and put all images into
Drawable. You renamed those files with the same name to something more obvious like
Company2-Logo.png. And it still doesn’t work.
// aapt resource value: 0x7f020020 public const int Icon = 2130837536;
Picture above: Android’s awesome resource handling code.
Due to the way resources are processed in Android, all file names are converted to C# identifiers. And you can resolve images by using their C# counterpart. This, unfortunately, means that only those file names which are valid C# identifiers are valid file names.
This means removing dashes and using underscores. This also means that your images starting with numbers are also invalid. Forget all those
13thStreet.pngh, use some “better” names.
Till’ next time, happy coding.
Published at DZone with permission of Toni Petrina, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.