如何更改 Xamarin.Forms 中的应用程序图标? [英] How to change application icon in Xamarin.Forms?
问题描述
我替换了所有地方的所有图像(我的意思是在 drawable 文件夹和所有 Windows Assets 文件夹和 iOS Resources 文件夹中),但它仍然向我显示应用程序的默认 Xamarin 图标.我也试过这段代码,但它似乎也不起作用.有人能告诉我解决办法吗?
[程序集:应用程序(Icon = "@drawable/icon")]
更新图标和名称 (Android)
如果您更改了图标名称,请确保更新 MainActivity.cs
[Activity(Label = "MyName", Icon = "@mipmap/myicon", Theme = "@style/MainTheme"]公共类 MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity{}
您可能还需要更新对 icon.xml
中的 launcher_foreground
和 mipmap-anydpi 中的
文件夹.icon_round.xml
的引用
总结(Android)
- 用新图标替换 mipmap 文件夹中的
png
- 如果您已经清理并重新构建了项目,但您的新图标仍未部署:从 Android 项目目录中删除
obj
文件夹
图标未更新时的问题 (Android)
Xamarin Forms/Android 在每个 mipmap 文件夹(mipmap-mdpi、mipmap-hdpi、mipmap-xhdpi 等)中放置 2 个图标 - icon.png
和 launcher-foreground.png代码>.
替换每个 mipmap 文件夹中的这两个图像.我保留了相同的名称,但应该可以使用不同的名称.
如果应用程序在清理/重新构建解决方案后仍然使用默认图标进行部署,则原始/默认图标可能仍然存在于 Android 项目 obj
文件夹中.解决方法是从Android项目目录中删除obj
文件夹.
iOS
对于 iOS,请参阅 使用资产目录管理图标.下面提供了从链接页面中提取的摘要:
<块引用>对于图标,可以将特殊的 AppIcon
图像集添加到应用项目的 Assets.xcassets
文件中.
要使用资产目录,请执行以下操作:
- 在解决方案资源管理器中双击 Info.plist 文件.
- 点击 Visual Assets 选项卡,然后点击 App Icons 下的 Use Asset Catalog 按钮.
- 从解决方案资源管理器中,展开资产目录文件夹.
- 双击媒体文件以在编辑器中打开它.
- 在属性资源管理器"下,开发人员可以选择所需的不同类型和大小的图标.
- 点击给定的图标类型并选择所需类型/大小的图像文件.
- 单击打开"按钮将图像包含在项目中并将其设置在 xcasset 中.
MacOs
MacOs 的指南是 Xamarin 的应用程序图标.Mac 应用.您需要考虑以下步骤:
<块引用>- 所需的图像大小和文件名
- 打包图标资源
- 使用图标
在上面链接的文档中有详细说明.
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")]
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)
- Replace both
png
's in mipmap folders with your new icon - 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
.
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 theAssets.xcassets
file in the app's project.To use an Asset Catalog, do the following:
- Double-click the Info.plist file in the Solution Explorer.
- Click on the Visual Assets tab and click on the Use Asset Catalog button under App Icons.
- From the Solution Explorer, expand the Asset Catalog folder.
- Double-click the Media file to open it in the editor.
- Under the Properties Explorer the developer can select the different types and sizes of icons required.
- Click on given icon type and select an image file for the required type/size.
- 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:
- Required image sizes and filenames
- Packaging the icon resources
- Using the icon
detailed in the linked docs above.
这篇关于如何更改 Xamarin.Forms 中的应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!