【问题标题】:Adaptive Icon not working自适应图标不起作用
【发布时间】:2018-03-30 17:24:29
【问题描述】:

清单:

<application
    android:name="..."
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/MyTheme"
    tools:replace="icon,label,theme,name,allowBackup">

文件夹下mipmap-anydpi-v26我已经定义了ic_launcher.xml

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

这是我的文件夹结构:

build.gradle:

compileSdkVersion = 26
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
targetSdkVersion = 25
minSdkVersion = 18

而且,我使用的是 android studio 3.0

但最终结果是我得到了一个默认的 android 图标,而不是我提供的那个。

我也尝试将前景 png 放入所有密度文件夹(mipmap-xhdpi 等),尽管我在测试时使用了相同的 png

【问题讨论】:

  • 你用的是模拟器还是真机?如果是设备,是什么类型的?
  • 在 sdk 26 上使用模拟器,nexus 5x
  • 很难说...您是否尝试过更新构建工具?另一件事是模拟器不支持图标变化。
  • @KarolKulbaka 这是构建工具版本,如果您愿意,请将其作为答案提交,否则我会
  • 您是否尝试将此android:roundIcon="@mipmap/ic_launcher_round" 添加给您AndroidManifest?看看这个。 Adaptive Icons

标签: android android-8.0-oreo


【解决方案1】:

自适应图标需要 API 26,因此您需要将构建工具更新到至少 26.0.0 版本

【讨论】:

  • 谢谢,这非常有帮助
  • 我将构建工具设置为 26.0.2,但它仍然显示默认图标。
  • 在 Android Studio 中转到帮助 -> “查找操作...”键入“图像资产”并单击以打开它。在那里您可以指定前景图像、背景图像(或颜色),它将自动生成所有启动器图像和 xml 文件。
  • @toobsco42 我遇到了同样的问题,但事实证明是因为我错误地使用了错误的 xmls 定义(基本上我使用了 Android Studio 建议的自动修复,这在这方面是个坏主意案例)。
  • 我在官方文档https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive中没有看到对构建工具的要求,这是在哪里记录的?
【解决方案2】:

我也遇到了同样的问题,下面是我解决这个问题的方法

  1. 右键资源->新建->ImageAsset

  2. 如下图所示选择ic_launcher_background图标和ic_launcher_foreground

  1. Android studio 在资源mipmap(anydpi-v26)下创建一个ic_launcher.xml

     <?xml version="1.0" encoding="utf-8"?>
    <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>
    
  2. 现在在 Manifest.XML 中,声明图标和圆形图标 如下图所示

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    
    
                    .......</application>
    

    是的,就是这样,在它出现的任何设备上运行您的应用

【讨论】:

  • 是的。我使用的是drawable/ic_launcher 而不是mipmap/ic_launcher。不经常使用,我认为没有很好的记录。
  • 有点,是的,我们需要挖掘更多细节,developer.android.com/guide/practices/ui_guidelines/…
  • 成功。是的,如果你替换你的启动器图标,你需要记住替换你的可绘制为 mipmap。这个让我很好。
【解决方案3】:

我在显示自适应图标时遇到问题。事实证明我没有做错任何事。我在 Android Studio 中做了一个“清洁项目”后,它开始工作了。

【讨论】:

  • 我也一切正常。我正要继续尝试不同的配置。谢谢!
【解决方案4】:

ic_launcher.xml应该是这样的

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon
    xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/white"/>
    <foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>

【讨论】:

    【解决方案5】:

    我尝试使用&lt;ImageView&gt; 对其进行调试。当我这样做时,我得到了一个以以下结尾的回溯:

    Caused by: java.lang.IllegalArgumentException: Path string cannot be empty.
    

    原来我的ic_launcher_foreground.xml 有一些&lt;path&gt; 元素具有空的android:pathData 属性。

    删除那些空的&lt;path&gt;s 使图标生效!

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 2013-02-04
      • 1970-01-01
      • 2017-11-10
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多