0

The application I have is set up like this:

{
    [Activity(Label = "Japanese", Icon = "@drawable/ic_launcher_mdpi", Theme = "@style/MainTheme")]
    public class MainActivity : FormsAppCompatActivity
    {

But the folders look like this:

enter image description here

I also have this:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <color android:color="@color/launcher_background"/>
    </item>
    <item>
        <bitmap android:src="@drawable/ic_launcher_xxhdpi"
                android:tileMode="disabled"
                android:gravity="center"
                android:layout_gravity="center"/>
    </item>
</layer-list>

Something doesn't seem quite right.

Can someone tell me how I can specify the icon and have it use the different size versions depending on the device.

Alan2
  • 23,493
  • 79
  • 256
  • 450
  • [Set icon for Android application](https://stackoverflow.com/questions/5350624/set-icon-for-android-application) – VahidShir Jun 16 '19 at 08:51
  • Sorry, but the link you provide was from 8 years ago and not for Xamarin Forms. Although it might still be valid I am looking for something more up to date as things seems to change monthly and 8 years is an eternity for software dev. – Alan2 Jun 16 '19 at 09:07

2 Answers2

0
  1. Create an icon and name it for example icon.png and put it in the "drawable" folder(the biggest resolution version of icon). Note: You can also provide different icons for different resolutions(to fit to different devices sizes) by creating same icon with exactly same name i.e icon.png and put them in related folders. For example your 192*192 icon.png must be put in drawable-xxxhdpi folder. To understand what resolution each folder maps to read this link.

  2. Reference the above icon as app's launcher icon in Android's MainActivity:

    [Activity(Label = "My App", Icon = "@drawable/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity { protected override void OnCreate(Bundle bundle) { //... } }

You can also set it in manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest >
    <application android:label="My App" android:icon="@drawable/icon"></application>
</manifest>

According to your photo it seems you should remove all "ic_launcher_***" in "drawable" folder and set app's icon in manifest and MainActivity as "@drawable/ic_laincher", because they are already put in related folders.

VahidShir
  • 2,066
  • 2
  • 17
  • 27
  • So what' are the mipmap folders for ? – Alan2 Jun 16 '19 at 11:16
  • According to [this answer](https://stackoverflow.com/a/24066445/5941852) if we're building a single APK for all devices densities, the mipmap is not different than drawable. – VahidShir Jun 16 '19 at 11:35
0

1. mipmap technology

Android has added mipmap technology in API level 17, and supports mipmap technology for rendering bitmap images to improve the speed and quality of rendering.

By Bitmap method public final void setHasMipMap (Boolean hasMipMap) , API can make the system renderer try to turn on Bitmap mipmap technology. However, this method can only be used to suggest that the system turn this function on, and it is up to the system to decide whether it is actually turned on or not. The difference between mipmap and drawable below the res directory is the difference between whether this setting is enabled or not. Images in the mipmap directory setHasMipMap is true and drawable setHasMipMap is false by default.

2. Why use mipmap folder?

Different home screen launcher apps on different devices show app launcher icons at various resolutions. When app resource optimization techniques remove resources for unused screen densities, launcher icons can wind up looking fuzzy because the launcher app has to upscale a lower-resolution icon for display. To avoid these display issues, apps should use the mipmap/ resource folders for launcher icons. The Android system preserves these resources regardless of density stripping, and ensures that launcher apps can pick icons with the best resolution for display.

3.use mipmap folder

Make sure launcher apps show a high-resolution icon for your app by moving all densities of your launcher icons to density-specific res/mipmap/ folders (for example res/mipmap-mdpi/ and res/mipmap-xxxhdpi/). The mipmap/folders replace the drawable/ folders for launcher icons. For xxhpdi launcher icons, be sure to add the higher resolution xxxhdpi versions of the icons to enhance the visual experience of the icons on higher resolution devices.

Note:

1.Even if you build a single APK for all devices, it is still best practice to move your launcher icons to the mipmap/ folders.

2.The mipmap is just for the launcher icon, so the rest of the resource images should still be in our drawable directory.

Jessie Zhang -MSFT
  • 9,830
  • 1
  • 7
  • 19