Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, May 3, 2019 6:01 PM
I can understand the purpose of Android's mipmap folders for holding app launcher icons of different resolutions. What I don't understand is why it's necessary to create two icons each in these folders when a new project is created with Visual Studio (in my case VS 2017).
- Each of the folders has icon.png and launcher_foreground.png where the later is always x2.5 in pixel density. I am assuming that there is a good reason for this. Should I reproduce the same icons organization (two each per folder) as a requirement?
- Is it recommended (or even possible) to do image Source binding to the mipmap folders from XAML? I wanted to use an icon of certain resolution (if at all possible) but couldn't see an easy way of doing XAML binding which is implicitly done for the drawable folder. I suspect that android images are restricted to the drawable folder since I haven't come across bindings to different folders like in iOS or UWP project.
All replies (4)
Monday, May 6, 2019 6:12 AM âś…Answered
Using mipmaps for your launcher icon is described as best practice by the Android team. The default template places two icons in that folder(icon and launcher*foreground) because we could use Adaptive icons on level 26 and later: https://developer.android.com/guide/practices/ui*guidelines/icon*design*adaptive. And you can find the icon.xml and icon_round.xml files in the mipmap-anydpi-v26 folder. It defined the Adaptive icons with foreground and background images. So there're two workarounds for setting application's icon after API 26
- Use icon.png directly
- USe Adaptive icons(icon.xml)
This is why you can see two image sources in each mipmap folders. Here, we need to know the usage of anydpi
and v26
.
- anydpi: These resources take precedence in any dpi. So even if you have mipmap-hdpi or mipmap-mdpi matching with current devices density, resource from mipmap-anydpi will always be picked up.
- anydpi-v26: This is an additional filter over just anydpi. This says resources will always be picked up from anydpi-v26 regardless of devices density only if SDK/API level is 26 or higher(Oreo).
As a result, your application will search that folder first. If it finds the icon file there, it will apply it. If not it will use the corresponding dpi mipmap folders.
Is it recommended (or even possible) to do image Source binding to the mipmap folders from XAML? No. If you want to load local images, you have to place them in the Resources/drawable directory with Build Action: AndroidResource. Refer to this documentation for more details: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images
Sunday, May 5, 2019 4:35 AM
Image and Incon in your Rep Drawable for your Project
Monday, May 6, 2019 6:39 AM
Thank you @LandLu for the answer well explained. This is an amazing forum for learning. Wish I joined sooner.
Wednesday, January 6, 2021 5:37 PM
Thanks @LandLu very well explained.