Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
581 views
in Technique[技术] by (71.8m points)

c# - How to change application icon in Xamarin.Forms?

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")]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Updating Icon and Name (Android)

If you changed the icon name(s) please ensure you update the reference on MainActivity.cs

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

You may also need to update the reference to launcher_foreground in icon.xml and icon_round.xml in the mipmap-anydpi folder.

Summary (for Android)

  1. Replace both png's in mipmap folders with your new icon
  2. If you've cleaned and re-built project but still your new icons are not deploying: Delete obj folder from Android project directory

Issues if Icon Not Updated (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 the app still deploys with the default icons even after cleaning/re-built the solution 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...