I have adaptive XML icon, built from 3 drawables.
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<layer-list>
<item>
<shape>
<solid android:color="#fff" />
<size android:width="108dp" android:height="108dp" />
</shape>
</item>
<item android:drawable="@drawable/icon_abc"
android:width="54dp"
android:height="27dp"
android:top="27dp"
android:left="27dp" />
</layer-list>
</background>
<foreground>
<layer-list>
<item
android:width="108dp"
android:height="56dp"
android:drawable="@drawable/icon_foreground"
android:top="56dp"
/>
<item
android:width="54dp"
android:height="27dp"
android:drawable="@drawable/icon_pluseq"
android:left="27dp"
android:top="56.5dp"
/>
</layer-list>
</foreground>
</adaptive-icon>
Below is a preview from Android Studio.
But when I install my app on emulator (API v27), I see this:
I've read answers to that question before writing this. In the linked question problem was in unappropriate size of icon, but my icon has size 108x108dp and inner foreground has size 72x72dp (as it is shown in the preview). In this case I see that icon is not centered at all.
UPD: In the Overview window icon displays properly:
UPD 2: If I use classic approach and provide two webp
mipmaps for background and foreground like below, then icon displays as expected.
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@mipmap/icon_xxhdpi_background" />
<foreground android:drawable="@mipmap/icon_xxhdpi_foreground" />
</adaptive-icon>
But with that approach I can't implement xml drawable e.g. for scaling mipmaps for round version of icon. That means I'm forced to store 2 differend versions of webp
icons (4 images) with total size of 10 KiB, that is 5 times bigger than 2 KiB of xml version.
UPD 3: Below is a comparison of output for xxhdpi
and hdpi
screens respectively
As I can see, results are different. Maybe there's a sort of resolution issue, maybe in resource folders naming.
UPD 4: I've checked possible solution, suggested in comments.
Using bitmap
s instead of drawable
references makes no difference since final result is properly builded (as I can see in Overview window), but "desktop" version of icon is still displays improperly.
Seems like this is a system bug :(
Just make a vector of your icon.