Search code examples
androidandroid-image

How to show an entire image for a launcher icon in Android


I have the following png file house.png in the drawable folder of my Android app

enter image description here

I would like to use it as a launcher icon and thus I use it in this XML layout file:

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background"/>
    <foreground android:drawable="@drawable/house"
        android:scaleType="fitEnd"
        android:gravity="center"/>
</adaptive-icon>

with ic_launcher_background

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF"/>
</shape>

Unfortunately, just a part of the figure is shown as you can see here in the screenshot: enter image description here. Also when installing it on a real device, only a part of the image is shown. I tried to decrease the resolution, but this did not help as the image is then just being displayed with lower quality (less pixels).

How can I use the entire image as a launcher icon?


Solution

  • You need to leave a margin in your icon image, as Android uses adaptive icons which can change shape in various situations.

    You can learn about this and find the guidelines here.