自适应图标不起作用

Sia*_*ash 13 android android-8.0-oreo

表现:

<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">
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

这是我的文件夹结构: 在此输入图像描述

的build.gradle:

compileSdkVersion = 26
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
targetSdkVersion = 25
minSdkVersion = 18
Run Code Online (Sandbox Code Playgroud)

而且,我正在使用android studio 3.0

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

我也尝试将前景png放在所有的密度文件夹(mipmap-xhdpi等)中,虽然我在执行此操作时只使用相同的png进行测试

Kar*_*aka 9

自适应图标需要API 26,因此您需要将buildtools更新为至少26.0.0版本

  • 我将构建工具设置为26.0.2,但它仍然显示默认图标. (7认同)
  • 在Android Studio中,转到帮助 - >"查找操作...",键入"图像资源",然后单击以打开它.在那里,您可以指定前景图像,背景图像(或颜色),它将自动生成所有启动器图像和xml文件. (3认同)

Sur*_*agi 5

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

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

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

在此输入图像描述

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

     <?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>
    
    Run Code Online (Sandbox Code Playgroud)
  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>
    
    Run Code Online (Sandbox Code Playgroud)

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