How to change application icon in Xamarin.Forms?

C#Cross Platformxamarin.forms

C# Problem Overview


I replaced all the images everywhere (by this I mean in drawable folders and all Windows Assets folders and iOS Resources folder), but it still shows me the default Xamarin icon for the app. I tried this code, too, but it doesn't seem to work either. Can someone tell me the solution?

[assembly: Application(Icon = "@drawable/icon")]

C# Solutions


Solution 1 - C#

Updating Icon and Name (Android)

If you changed the icon file name please ensure you update the Icon reference in MainActivity.cs:

[Activity(Label = "MyName", Icon = "@mipmap/myicon", Theme = "@style/MainTheme"]    
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{ 
}

You should also update the names of icon.xml and icon_round.xml in the mipmap-anydpi folder to match to new icon name. If launcher-foreground.png was renamed then update the value of <foreground...> in corresponding icon.xml.

Summary (Android)

  1. Replace the png's in mipmap folders with your new icon
  2. If name was changed, update Icon value in MainActivity.cs
  3. If name was changed, update name of (or create a new copy of) icon.xml and icon_round.xml
  4. If name of launcher-foreground.png was changed then update value in icon.xml. Eg:
    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
      <background android:drawable="@color/my_launcher_background"/>
      <foreground android:drawable="@mipmap/my_launcher_foreground"/>
    </adaptive-icon>
    
  5. If name wasn't changed and you've cleaned and re-built project but still your new icons are not deploying: Delete obj folder from Android project directory

Details and Issues if not updating (Android)

Xamarin Forms/Android puts 2 icons in each mipmap folder (mipmap-mdpi, mipmap-hdpi, mipmap-xhdpi, etc) - icon.png and launcher-foreground.png.

enter image description here

Replace both these images in each of the mipmap folders. I kept the same names but it should be possible to use a different name.

If you rename launcher-foreground.png then you must update the values in icon.xml and icon_round.xml (or their equivalent new names). The value in the <foreground...> tag references the icon/png. So, if launcher-foreground.png was updated to my_launcher-foreground.png this should be reflected in the icon.xml (see step 4 in summary above).

If the icons still don't update even after cleaning/re-building it could be that the original/default icons still existed in the Android project obj folder. The solution is to delete the obj folder from the Android project directory.


iOS

For iOS, please see Managing Icons with Asset Catalogs. A summary taken from the linked page is provided below:

> For icons, a special AppIcon image set can be added to the Assets.xcassets file in the app's project. > > To use an Asset Catalog, do the following: > > 1. Double-click the Info.plist file in the Solution Explorer. > 2. Click on the Visual Assets tab and click on the Use Asset Catalog button under App Icons. > 3. From the Solution Explorer, expand the Asset Catalog folder. > 4. Double-click the Media file to open it in the editor. > 5. Under the Properties Explorer the developer can select the different types and sizes of icons required. > 6. Click on given icon type and select an image file for the required type/size. > 7. Click the Open button to include the image in the project and set it in the xcasset.


MacOs

The guide for MacOs is Application icon for Xamarin.Mac apps. You need to consider the following steps:

> 1. Required image sizes and filenames > 2. Packaging the icon resources > 3. Using the icon

detailed in the linked docs above.

Solution 2 - C#

For Android try to set the icon app like this:

[Activity(Icon = "@drawable/icon")]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
     .....
}

Make sure that you have changed all the icon images on all drawable folders ( drawable, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi ).

For iOS I like set the app icons and splash screen with Asset Catalogs, here you can find a guide to how to use it:

https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_images/app-icons/

Solution 3 - C#

For iOS in visual studio...

Step1: Generate all the app icons from https://appicon.co/

Step2: In solution explorer, under iOS project, expand 'Asset Catalogs' and double click on 'Assests'. You can change the existing 'AppIcon' icons or Add a new Asset and attach the icons.

enter image description here

This is how you add a new asset...

enter image description here

Step3: In solution explorer, under iOS project, double click on Info.plist. Go to 'Visual Assets' tab, click on 'App Icons' and change the 'Source' to the asset that you just created.

Done.

Hope this helps someone!

Solution 4 - C#

Answer is deprecated

If I understood you correctly, for iOS project: Properties -> iOS Application

For Android: Properties -> Android Manifest

Solution 5 - C#

I had the same problem, but the following helped resolve it:

  1. Go to MainActivity.cs (in the Solution Explorer)
  2. Look for where it says 'Icon ='
  3. Change the location of the Icon, but don't include the extension, i.e. jpg, png, etc. (For ex. Icon = "@drawable/weatherIcon")
  4. Save the file
  5. Restart debugging (the little restart icon beside the stop and pause icon around the top right-hand side of your screen)

If you get stuck on any part of this check out this short video from 02:47 onwards https://youtu.be/5g8lWPQZFxs?t=167. It helped me a lot.

Solution 6 - C#

Try to replace all the icon on iOS project > Properties > iOS Application > Iphone Icons/IPad Icons. I change all of them, the settings icon do change. Images that on Resouces can be created by just insert images on there.

Solution 7 - C#

Tested this today and noticed that you only need to change the icon images in all drawable folders,

              drawable,
              drawable-hdpi,
              drawable-xhdpi
              drawable-xxhdpi.

Depending on the device it's going to use different images. For me i used "Visual Studio Android Emulator" using:

              - 5" KitKat(4,4) XXHDPI Phone (Android 4,4 - API 19)

Did not need to uninstall and reinstall the app in the emulator, it updated on it's own after starting the project with "build" checked in the menu Build/Configuration manager.

On top of that no code changes were made!

Solution 8 - C#

If you replace the Icon.png and still nothing changed on the device, than change "Copy to Output Directory" propertiy to "Copy if newer" or "Copy always". That was my solution.

Solution 9 - C#

All of these solutions are great, but

THE SIMPLEST WAY:

You can now just use ResizetizerNT's nuget package and upload one svg file and set IsAppIcon to true. That should generate everything needed. If the existing app icon is icon.png, just name the svg to icon.svg and it should automatically work.

Alternatively, you can also add another SVG for the background in order to support adaptive icons on Android.

Context: ResizetizerNT was created by the Xamarin.Forms/MAUI Engineering Manager, Jonathan Dick

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSzandiView Question on Stackoverflow
Solution 1 - C#haldoView Answer on Stackoverflow
Solution 2 - C#Victor MadurgaView Answer on Stackoverflow
Solution 3 - C#user10398433View Answer on Stackoverflow
Solution 4 - C#Yehor HromadskyiView Answer on Stackoverflow
Solution 5 - C#Richard OgujawaView Answer on Stackoverflow
Solution 6 - C#HaskellView Answer on Stackoverflow
Solution 7 - C#Victor ErikssonView Answer on Stackoverflow
Solution 8 - C#NITROView Answer on Stackoverflow
Solution 9 - C#SaamerView Answer on Stackoverflow