Icons in Android mipmap folders

davedave Member ✭✭
edited May 3 in Xamarin.Android

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.

Best Answer

  • LandLuLandLu Xamurai
    Accepted Answer

    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

    1. Use icon.png directly
    2. 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

Answers

  • ahmidiahmidi Member

    Image and Incon in your Rep Drawable for your Project

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    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

    1. Use icon.png directly
    2. 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

  • davedave Member ✭✭
    Thank you @LandLu for the answer well explained. This is an amazing forum for learning. Wish I joined sooner.
Sign In or Register to comment.