How to adjust size of vector icon in launcher

Viewed 119

My app's launcher icon is vector-drawn (as opposed to image-drawn). It is launched with

<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
      <background android:drawable="@color/appColorDark" />
      <foreground android:drawable="@drawable/ic_myIcon" />
</adaptive-icon>

However, the icon is severely cropped (i.e. only partially visible) in the preview display (and therefore in the ultimate launcher icon).

QUESTION: is there any attribute in XML (or alternatively, in code) I can use to scale the icon down, so that it fits nicely (i.e. with the required padding) in the previewed colored background? That code would also come in handy whenever I want to use the same vector file somewhere else in the app.

My solution now is to go back to Inkscape, reset the borders, resave the file in Android Studio, have a look in the preview, back to Inkscape etc. till it fits. Not ideal.

3 Answers

I suggest you to create a launcher icon in the form of a mipmap where the launcher will adjust to the device on which the application will be installed. of course you can easily create the mipmap file here : https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html

you can make some adjustments here. of course this way is easier and better I think. you just need to overwrite the existing mipmap file with the new mipmap file.

I hope this helps

You can wrap the pathData in your ic_myIcon.xml drawable with group tag and then play the scale.

<!--Reduce scaleX and scaleY  until desired size is achieved (note: 1 = 100%).
   You may also need to adjust the position (translateX and translateY) after scale adjs.
-->
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
            ...
         >
        
            <group 
                android:scaleX="1" 
                android:scaleY="1"
                android:translateX="0"
                android:translateY="0"
                >
              
                <path
                    android:pathData=.../>

            </group>
        </vector>

You can create the launcher icon using Image asset studio which is a preferred way and recommended by android dev team. image asset studio

Related