c# - 如何更改 Xamarin.Forms 中的应用程序图标?

标签 c# cross-platform xamarin.forms

我替换了所有位置的所有图像(我的意思是在可绘制文件夹和所有 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.xmlmipmap-anydpi文件夹以匹配新图标名称。如果launcher-foreground.png重命名然后更新 <foreground...> 的值在相应的icon.xml .

总结(安卓)

  1. 替换 png在带有新图标的 mipmap 文件夹中
  2. 如果更改了名称,请更新 Icon MainActivity.cs 中的值
  3. 如果更改了名称,请更新名称(或创建新副本)icon.xmlicon_round.xml
  4. 如果名字是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>
    
  5. 如果名称未更改并且您已清理并重新构建项目,但您的新图标仍未部署:删除 obj Android 项目目录中的文件夹

如果不更新(Android)的详细信息和问题

Xamarin Forms/Android 在每个 mipmap 文件夹中放置 2 个图标(mipmap-mdpi、mipmap-hdpi、mipmap-xhdpi 等)- icon.pnglauncher-foreground.png .

enter image description here

替换每个 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 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.

苹果

MacO 的指南是 Application icon for Xamarin.Mac apps .您需要考虑以下步骤:

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

在上面的链接文档中有详细说明。

关于c# - 如何更改 Xamarin.Forms 中的应用程序图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37945767/

相关文章:

windows - 在 Windows 上运行 Mac OS 应用程序?

cordova - 如何开发跨平台的QR码阅读器?

xamarin.forms - Xamarin Forms ScrollView 上的 ScrollOrientation.Both

c# - Xamarin Forms 使用字体大小缩放组件

c# - 以编程方式从 XML 模式生成测试 XML

c# - Linq to SQL Left Join、Order 和 Group By Count

c++ - 跨平台绘图库

c# - 为什么路径信息路由在 ASP.NET MVC 示例中不起作用?

c# - 将 Canvas 大小调整为相邻标签的文本高度

xamarin - Visual Studio 2015 + Xamarin > 在运行应用程序之前选择一个有效的设备