我替换了所有位置的所有图像(我的意思是在可绘制文件夹和所有 Windows Assets 文件夹和 iOS 资源文件夹中),但它仍然显示应用程序的默认 Xamarin 图标。我也试过这段代码,但它似乎也不起作用。谁能告诉我解决方案?
[assembly: Application(Icon = "@drawable/icon")]
最佳答案
更新图标和名称(Android)
如果您更改了图标文件名,请确保更新 Icon
引用 MainActivity.cs
:
[Activity(Label = "MyName", Icon = "@mipmap/myicon", Theme = "@style/MainTheme"]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
}
您还应该更新 icon.xml
的名称和 icon_round.xml
在mipmap-anydpi
文件夹以匹配新图标名称。如果launcher-foreground.png
重命名然后更新 <foreground...>
的值在相应的icon.xml
.
总结(安卓)
- 替换
png
在带有新图标的 mipmap 文件夹中 - 如果更改了名称,请更新
Icon
MainActivity.cs
中的值 - 如果更改了名称,请更新名称(或创建新副本)
icon.xml
和icon_round.xml
- 如果名字是
launcher-foreground.png
已更改,然后更新icon.xml
中的值.例如:<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>
- 如果名称未更改并且您已清理并重新构建项目,但您的新图标仍未部署:删除
obj
Android 项目目录中的文件夹
如果不更新(Android)的详细信息和问题
Xamarin Forms/Android 在每个 mipmap 文件夹中放置 2 个图标(mipmap-mdpi、mipmap-hdpi、mipmap-xhdpi 等)- icon.png
和 launcher-foreground.png
.
替换每个 mipmap 文件夹中的这两个图像。我保留了相同的名称,但应该可以使用不同的名称。
如果您重命名 launcher-foreground.png
那么您必须更新icon.xml
中的值和 icon_round.xml
(或它们的等效新名称)。 <foreground...>
中的值标签引用图标/png。所以,如果 launcher-foreground.png
已更新为 my_launcher-foreground.png
这应该反射(reflect)在 icon.xml
中(请参阅上面摘要中的步骤 4)。
如果图标即使在清理/重建后仍未更新,则可能是原始/默认图标仍然存在于 Android 项目中 obj
文件夹。解决方案是删除obj
Android 项目目录中的文件夹。
iOS
对于 iOS,请参阅 Managing Icons with Asset Catalogs .下面提供了从链接页面获取的摘要:
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.
苹果
MacO 的指南是 Application icon for Xamarin.Mac apps .您需要考虑以下步骤:
- Required image sizes and filenames
- Packaging the icon resources
- Using the icon
在上面的链接文档中有详细说明。
关于c# - 如何更改 Xamarin.Forms 中的应用程序图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37945767/