【问题标题】:Xamarin Oreo Adaptive IconsXamarin Oreo 自适应图标
【发布时间】:2019-12-22 02:49:55
【问题描述】:

你们中是否有人成功使用了 Oreo 中引入的 xamarin android 的“自适应图标”?

如果 .png 图像放置在 Drawable 文件夹中,我设法使它工作,但如果它们放置在 MipMap 文件夹中,则不是。

我已遵循此链接中的指南,并且在使用 Android Studio 时也可以使用...我觉得很奇怪?

https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive.html

【问题讨论】:

  • 我想当你的图像在 mipmap 中时你希望它工作?
  • 我想在 mipmap 文件夹中拥有旧的 launcher_icons,然后我想要拥有自适应图标 xml,就像他们在链接“res/mipmap-anydpi/ic_launcher.xml”中一样。 “...但是这样做会显示默认启动器图标...我发现的唯一解决方法是将ic_launcher.xml放在drawble-v26中,并将launcher_icons也移动到drawble文件夹中,在为了引用像“drawable/ic_launcher”这样的图像
  • 分享一些代码然后可能是
  • 有什么更新吗?我无法让这个工作。

标签: xamarin.android android-8.0-oreo


【解决方案1】:

感谢this blog post,我能够在我的 Xamarin.Forms Android 应用中使用自适应图标。

涉及的步骤

  1. 使用 Android Studios Image Asset Studio 创建一个自适应图标(请注意,您需要一段时间才能在 Android Studio 中实际添加一个新的 Image Asset,因为编辑器正在首次初始化。)
  2. 创建启动器项后,您可以在文件资源管理器中打开 res 目录。
  3. 将所有mipmap-*-文件夹复制到Xamarin.Forms Android 项目Resources 目录中。
  4. 更新AndroidManifest.xml 以包含新的iconroundIcon 资产
<application android:label="MyApp"
               android:icon="@mipmap/ic_launcher"
               android:roundIcon="@mipmap/ic_launcher_round"
               android:appCategory="productivity"></application>
  1. 在 MainActivity 中还更新 IconRoundIcon
namespace MyApp.Droid
{
    [Activity(Label = "MyApp", Icon = "@mipmap/ic_launcher", RoundIcon = "@mipmap/ic_launcher_round", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

【讨论】:

  • 这篇博文的评分为 2 分(满分 5 分),但至少是这样!嘿 Xamarin,你想提供一个工作示例,这样人们就不必在一些愚蠢的图标上浪费时间?我发现您不想要 mipmap-anydpi-v26 文件夹或关联的 xml 文件。我猜 xml 文件是类似 svg 格式的 Xamarin 图标,而 anydpi 文件夹实际上优先于其他文件夹!
  • 我需要从 drawable 目录中添加 ic_launcher_background.xml 和 ic_launcher_foreground.xml 才能让它工作。
  • 对于现在发现这个问题的任何人,为了完成这项工作,我必须手动将 mipmap 文件夹添加到 .csproj 文件中:&lt;AndroidResource Include="Resources\mipmap-*\ic_launcher*"/&gt;(这将包括来自 mipmap-anydpi- 的图标和 xml 文件v26。)由于我的图标使用纯色背景,我还必须手动包含Resources\ic_launcher_background.xml,并且anydpi 可能还需要您包含来自drawable 的xml。 (Visual Studio 可能会自动完成所有这些,我使用的是 JetBrains Rider。)
【解决方案2】:

据说 xamarin android mipmap 文件夹中有一个错误,在 hereRelease Notes 中都有很好的解释

还有一些 bugzilla 报告:

https://bugzilla.xamarin.com/show_bug.cgi?id=56146

https://bugzilla.xamarin.com/show_bug.cgi?id=59904

希望对你有帮助!

【讨论】:

  • 感谢您的帖子!但我的问题不是我找不到 mipmap 文件,或者我得到任何构建错误......我在 mipmap 文件夹中的启动器图标工作正常。但是有一个问题,当尝试使用位于“mipmap-anydpi-v26”中的自适应图标时
  • xamarin 中的 mipmap 文件夹有很多错误是我想指出的,(已经工作一年了!)无论如何,如果您找到解决方案,请随时标记我!谢谢。
  • 确定:) 谢谢。我会的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
  • 1970-01-01
  • 2018-03-30
  • 2018-12-13
  • 2020-08-28
  • 2018-05-23
  • 2020-07-18
相关资源
最近更新 更多