manifest:
<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">
under the folder mipmap-anydpi-v26
I have defined 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
AND, I'm using android studio 3.0
but the end result is that I get a default android icon instead of the one I provided.
I've also tried putting the foreground png in all of the density folders (mipmap-xhdpi, etc), although I used the same png for all when I did this just for testing
自适应图标需要API 26,因此您需要将buildtools更新为至少26.0.0版本
I too have faced the same issue, here is how I have fixed this issue
Right click on resource -> New -> ImageAsset
Choose the ic_launcher_background icon and ic_launcher_foreground as shown in below screen
Android studio creates an ic_launcher.xml under resource mipmap (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>
Now inside the Manifest.XML, declare the icon and round icon something shown in like below
<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>
Yes that's all and Run your app on any device it appears
ic_launcher.xml should be like this
<?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>
I tried to debug it using an <ImageView>
. When I did so, I got a backtrace ending with:
Caused by: java.lang.IllegalArgumentException: Path string cannot be empty.
Turns out my ic_launcher_foreground.xml
had some <path>
elements with empty android:pathData
attributes.
Deleting those empty <path>
s made the icon work!
I had issues getting my adaptive icon to display. Turns out I had done nothing wrong. It started working after I did a 'Clean Project' in Android Studio.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.