Skip to content

Commit dae7898

Browse files
authored
Compensate for Android launcher icon scaling (#424)
Fixes #410 The launcher images created by `capacitor-assets generate` are correct, but the Android platform itself is displaying them scaled and cropped. We can compensate for that by defining an inset in the launcher XML. Credit for this approach goes to: https://stackoverflow.com/questions/66593626/why-does-adaptive-icon-generated-by-android-studio-crop-images-so-much-to-make-u The workaround that twoco pointed out on the linked issue involves adding padding to the icon so that the desired icon size was 2/3 of the actual width. Using those numbers, I added a padding of ~1/6 to each edge, so ~1/3 in total for each dimension. I tested this in android studio. I saw that the icon was fully visible in the launcher. I also tried it with background image that had circles touching the image edges, and I confirmed that they were not visible before this change and *were* visible at the edge of the image after this change.
1 parent 076a2e6 commit dae7898

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/platforms/android/index.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,12 @@ export class AndroidAssetGenerator extends AssetGenerator {
361361
const icLauncherXml = `
362362
<?xml version="1.0" encoding="utf-8"?>
363363
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
364-
<background android:drawable="@mipmap/ic_launcher_background"/>
365-
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
364+
<background>
365+
<inset android:drawable="@mipmap/ic_launcher_background" android:inset="16.7%" />
366+
</background>
367+
<foreground>
368+
<inset android:drawable="@mipmap/ic_launcher_foreground" android:inset="16.7%" />
369+
</foreground>
366370
</adaptive-icon>
367371
`.trim();
368372

@@ -428,8 +432,12 @@ export class AndroidAssetGenerator extends AssetGenerator {
428432
const icLauncherXml = `
429433
<?xml version="1.0" encoding="utf-8"?>
430434
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
431-
<background android:drawable="@mipmap/ic_launcher_background"/>
432-
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
435+
<background>
436+
<inset android:drawable="@mipmap/ic_launcher_background" android:inset="16.7%" />
437+
</background>
438+
<foreground>
439+
<inset android:drawable="@mipmap/ic_launcher_foreground" android:inset="16.7%" />
440+
</foreground>
433441
</adaptive-icon>
434442
`.trim();
435443

0 commit comments

Comments
 (0)