【问题标题】:Legacy icon does not show when using adaptive icon使用自适应图标时不显示旧图标
【发布时间】:2017-11-10 17:37:43
【问题描述】:

我刚刚使用 android studio 中的Image Asset Studio 将我的应用图标转换为与 android o 的自适应图标兼容

当我现在在运行 API 25 的设备上运行我的项目时,我得到了默认的绿色 android 图标,而不是我的图标。

这是我的清单

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:allowBackup="false"
    android:roundIcon="@mipmap/ic_launcher_round"
    tools:replace="allowBackup"
    tools:ignore="GoogleAppIndexingWarning">

这些是图像资产工作室创建的文件

这只是一个 Android Studio 错误还是我遗漏了什么?

【问题讨论】:

  • 这里也一样。你解决了吗?
  • 对我来说,解决方案是改变启动器的主题,它已经改变了开发图标。

标签: android android-studio android-icons


【解决方案1】:

我遇到了同样的问题,并通过将我的 mipmap-anydpi 目录重命名为 mipmap-anydpi-v26 来解决它。

显然ic_launcher.xml 文件混淆了旧的 Android 版本,除了 O 之外,这对所有版本都隐藏了它。无论如何,我的图标现在适用于所有版本(至少到 SDK 11)。

【讨论】:

  • 我有 v26 目录,但我仍然在旧版 APIS 上获得默认的绿色 android。
  • @JPM,我建议你用一些源代码打开一个新问题(就像 OP 在这里所做的那样)。我非常有信心这种技术可以像宣传的那样工作,但无法猜测您的应用可能出了什么问题。
  • 原来我还有 mipmap-anydpi 目录和 mipmap-anydpi-v26。一旦我删除了 mipmap-anydpi,那么所有版本的图标都是正确的。
  • 这仍然是个问题吗?我正在使用mipmap-anydpi-v26,用户说无根像素启动器没有显示自适应图标,我想知道是不是因为这个。
  • 似乎仍然是个问题。
【解决方案2】:

解决方案是将适用于 API 级别 26 及更高级别的自适应图标的 mipmap-anydpi-v26/ic_launcher.xml 以及其他 API 级别的 ic_launcher.png(注意:不是 ic_launcher.xml)放在所有 mimpap 文件夹中。


解释

这是mipmap-anydpi 优先于所有其他mipmap-* 的基本问题。因此,如果在mipmap-anydpi 中找到资源,它将始终优先。现在mipmap-anydpi-v26 是上面的一个过滤器,它表示无论设备密度如何,都将始终选择来自mipmap-anydpi-v26 的资源仅当 API 级别为 26 或更高时(奥利奥)。

现在你的清单有android:icon="@mipmap/ic_launcher"

如果您的设备具有 API 级别 26 或更高版本,android 将选择使用 mipmap-anydpi-v26/ic_launcher.xml 并且一切正常。

当 API 级别低于 26 时会出现问题。Android 统计信息正在寻找名为 ic_launcher 的资源。由于 API 级别的限制,它永远不会去搜索mipmap-anydpi-v26。接下来,它将在mipmap-anydpi 中查找资源,如果不存在则查找实际密度资源,例如。 mipmap-mdpi

接下来,您不能将ic_launcher.xml 分配给低于 sdk 26 的 android 设备,因为它不知道自适应图标是什么。

因此,解决方案是将适用于 API 级别 26 及更高级别的自适应图标的 mipmap-anydpi-v26/ic_launcher.xml 以及其他 API 级别的 ic_launcher.png(注意:不是 ic_launcher.xml)放在所有 mimpap 文件夹中。

【讨论】:

    【解决方案3】:

    如果仍然无法正常工作,请检查您的 XML schmema,如果您使用 Android Studio 自动导入,它将无法正常工作,它应该是 /apk/res/android。代码如下:

    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
      <background android:drawable="@mipmap/ic_launcher_background"/>
      <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
    </adaptive-icon>
    

    【讨论】:

      【解决方案4】:

      我也遇到过同样的问题,解决方法如下。

      将您的ic_launcher.xmlic_launcher_round.xml 放在mipmap-anydpi-v26 中(确保您不应将ic_launcher.png/jpgic_launcher_round.png/jpg 放在同一个文件夹中)。

      将您的ic_launcher.png 放在 mipmap-hdpi/mdpi/xhdpi/xxhdpi/xxxhdpi 中(确保您不应将ic_launcher.xmlic_launcher_round.xml 放在同一个文件夹中)。

      通过这样做,您将不会在构建/运行项目时遇到任何错误。

      希望对遇到同样问题的人有所帮助...

      【讨论】:

        【解决方案5】:

        我会以一种非常简单的方式来总结一下。

        我使用 android studio 只是为了生成在我的 config.xml 文件中使用的源(图像的背景和前景层)。

        所以它看起来像这样:-

        <icon background="resources/android/icon/ldpi_background.png" density="ldpi" foreground="resources/android/icon/ldpi_foreground.png">
        

        以上配置适用于 Android API level > 25。

        这是旧版本 android 中遗留图标的主要问题

        根据cordova官方文档-旧版本的android不支持自适应图标-使用上面的config.xml,它只会选择前景部分作为后备图标,这就是您的图标在旧版本中看起来不太好的原因.

        所以我为此应用了以下修复(根据科尔多瓦官方文档)

        添加带有静态图像图标的 src 属性 - 因此在旧版本中,它将使用该图标而不是使用后备图标,而对于最新版本,它将优先考虑自适应图标,因此两者的问题都将得到解决。

        修复后配置将如下所示:-

        <icon background="resources/android/icon/ldpi_background.png" density="ldpi" foreground="resources/android/icon/ldpi_foreground.png" src="resources/android/icon/drawable-ldpi-icon.png"/>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-02-13
          • 1970-01-01
          • 2017-02-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-03-30
          相关资源
          最近更新 更多