必须声明元素自适应图标

Element adaptive-icon must be declared

我使用 Android Studio 2.3.3 稳定版并尝试为 Android O

创建自适应图标

我创建了文件夹 mipmap-anydpi-v26 和文件 ic_launcher.xml,内容如下

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

但是它说 "Element adaptive-icon must be declared"。 Target SDK 和构建工具都设置为 26.

它构建成功,但我没有任何设备来测试它,所以我的问题是 - 它有效吗?

P.S.: 前景有效 VectorDrawable

我建议您从 Android Studio Virtual Device Manager 创建一个 Android O 虚拟设备来测试自适应图标。我在 Android Studio 2.3.3 中也遇到了同样的错误。似乎 Android Studio 2.3.3 不支持自适应图标标签。为此,我们需要 Android Studio 3.0。

甚至 Android 开发者网站中的自适应图标文档也显示 Android Studio 3.0 屏幕截图

https://developer.android.com/preview/features/adaptive-icons.html

编辑:- 我已经检查并发现自适应图标在 Android Studio 2.3.3 的应用程序构建中工作正常,与 "Element adaptive-icon must be declared" 错误无关。

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>