表现:
<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,因此您需要将buildtools更新到至少26.0.0版本
我也面临同样的问题,这就是我如何解决这个问题
<?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>
<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>
是的,这就是所有并在它出现的任何设备上运行您的应用程序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中完成了“清洁项目”后开始工作了。