自适应图标不起作用

问题描述 投票:11回答:5

表现:

<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>

这是我的文件夹结构:enter image description here

的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进行测试

android android-8.0-oreo
5个回答
8
投票

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


1
投票

我也面临同样的问题,这就是我如何解决这个问题

  1. 右键单击资源 - >新建 - > ImageAsset
  2. 选择ic_launcher_background图标和ic_launcher_foreground,如下面的屏幕所示

enter image description here

  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> 是的,这就是所有并在它出现的任何设备上运行您的应用程序

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>

0
投票

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

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

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

删除那些空的<path>s使图标有效!


0
投票

我有问题让我的自适应图标显示。事实证明我没有做错任何事。我在Android Studio中完成了“清洁项目”后开始工作了。

© www.soinside.com 2019 - 2024. All rights reserved.