自适应图标不起作用

Adaptive Icon not working

清单:

<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

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

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>

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

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

原来我的 ic_launcher_foreground.xml 有一些 <path> 元素具有空 android:pathData 属性。

删除那些空 <path>s 使图标工作!

我在显示自适应图标时遇到了问题。结果证明我没有做错任何事。我在 Android Studio 中做了 'Clean Project' 之后它开始工作了。

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

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

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

  1. Android 工作室在资源 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>
    

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