Vector Application Icon for Android — A Complete Guide.

Vector Application Icon for Android—A Complete Guide.Digging through Android’s documentation, I’ve noticed that not only adaptive icons were added to the SDK for version 26, but also the ability to completely forget about raster app icons for the launc…


This content originally appeared on Level Up Coding - Medium and was authored by Roman Cinis

Vector Application Icon for Android—A Complete Guide.

Digging through Android’s documentation, I’ve noticed that not only adaptive icons were added to the SDK for version 26, but also the ability to completely forget about raster app icons for the launcher on the newest versions of Android. This means that you do not need to create a bitmap icon for each screen resolution at all, but use one/two vector files for all possible resolutions! Since raster icons are quite bulky you can save a lot of kilobytes in the size of the application. However, it does have some limitations, and I will describe them here, also as a complete description of the whole process of its preparation, including a video of it. The guide is also available in the Czech and Russian languages.

Before we start

Getting rid of bitmaps in an entire application is a dream of many optimizers. Especially if the application is not large, and PNG icons, (if not made correctly) consume almost a quarter of the total app size. But it has some drawbacks, let’s talk about them, maybe in your case a vector icon is not an option. So:

  • The vector format in Android OS was introduced in version 21, you can use vector images as application icons in the launcher only in versions 26 and higher. This means, that if your app has to support older Android versions as well — you will still have to provide raster icons for them. So there’s not much of a benefit here.
  • The vector format that’s used by Android is not the popular SVG/EPS/AI format — it’s the XML, and that means, it has very limited usage. This format doesn’t support styling attributes, i.e. any effects, blending, even the simplest shadows, blur. You can see at the beginning of the video what happens to the shadows — they just disappear. If you have quite a skillful graphic designer on your team, then in general, this limitation could be bypassed by converting shadows into simple gradients from full color to completely transparent, etc. If you don’t have a vector original at all, or there are too many effects there, probably the game is not worth the candle.

That’s where the downsides end. If your app needs to run on devices that are still supported by security patches (i.e., at the time of writing this article it’s SDK version 27+) or is using some kind of modern Android system/sensor/device features, the vector icon is a great choice. You can save on both app size and files for the icon — having only one or two vector images and a few files with their descriptions! Does that sound cool? Then below you’ll find the recipe for how to make it all happen.

Preparing the files

I won’t go into the details of creating the icon images, as they are absolutely identical to the other adaptive icons. There are literally tons of all sorts of templates for adaptive icons and tutorials for them on the internet, you can also use this website to compare your adaptive and regular Android icons or the parallax effects as well. In short, you can use them all, with the only difference — we’ll end up using SVG files rather than PNG files. That is, it will be one/two files, the first with the background, which should have the “safe area” for the parallax effect and the foreground file. In my example, I use a variant where the background is just a color, so I will have a single file with a color description and one file with vector graphics.

So if you have your SVG file(s) then the next step is to get Android Studio, but if you are developing apps for Android you already know this software. This free IDE can be downloaded at:

https://developer.android.com/studio

Important! Vector Assets can only be created with version 4.2.2 and higher.

Start the Studio, open your project, after loading choose the Project tab (first tab at the top left). In the folder with the resources, open the context menu with the right mouse click. Select the first item in it — “New”, then “Vector Asset”. The Asset Studio will open, then select the type: Local file and the path through the folder button. Check how the icon looks and click Next if you are satisfied. This will show you the path and name of your vector icon XML file. Repeat those steps for the second file, if you use vectors in both the foreground and background. Done.

Setting up configuration files

And so the images are ready, but your project does not yet know the path to them and how to display them. You will need to add/modify several files:

  • build.gradle — you need to enable support for vector files here, just add these two lines to the configuration and dependencies:
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}

dependencies {
implementation("com.android.support:appcompat-v7:23.2.0")
}
  • add the folder “mipmap-anydpi-v26” to the resources folder, i.e. as you can see from the name, these are the assets for any DPI in OS versions above 26. There will be two files: ic_launcher_round.xml and ic_launcher.xml in which you need to describe what to use as a background and what as a foreground. In my case, it is a color for the background and vector graphics for the foreground.
  • things described in the previous section have to be added to the “drawable” folder and if you used color as the background — describe this color in colors.xml inside the “values” directory.

In general, here is the list of changes that should show up in your VCS:

At least two new lines in your defaultConfig and dependencies at:
./app/build.gradle

The “mipmap-anydpi-v26” folder with 2 new files at:
./app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
./app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

At least one new foreground XML file in “drawable” folder:
./app/src/main/res/drawable/ic_launcher_foreground.xml

And either add color as a background:
./app/src/main/res/values/colors.xml
or use an image file:
./app/src/main/res/drawable/ic_launcher_background.xml (not presented in this guide)

Now the system knows how, where and what to use as a launcher’s application icon. Run a clean installation and check the results of your work. As you can see, the technical part is quite simple (compared to PNG icons).

In the link below you will find all the files you need from the example shown in the video. You can use them as a blueprint for your application. Thanks for reading!

https://gist.github.com/tsinis/7580343ef2c973be231b1c9ca4a52bb1


Vector Application Icon for Android — A Complete Guide. was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Roman Cinis


Print Share Comment Cite Upload Translate Updates
APA

Roman Cinis | Sciencx (2021-08-16T15:54:16+00:00) Vector Application Icon for Android — A Complete Guide.. Retrieved from https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/

MLA
" » Vector Application Icon for Android — A Complete Guide.." Roman Cinis | Sciencx - Monday August 16, 2021, https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/
HARVARD
Roman Cinis | Sciencx Monday August 16, 2021 » Vector Application Icon for Android — A Complete Guide.., viewed ,<https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/>
VANCOUVER
Roman Cinis | Sciencx - » Vector Application Icon for Android — A Complete Guide.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/
CHICAGO
" » Vector Application Icon for Android — A Complete Guide.." Roman Cinis | Sciencx - Accessed . https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/
IEEE
" » Vector Application Icon for Android — A Complete Guide.." Roman Cinis | Sciencx [Online]. Available: https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/. [Accessed: ]
rf:citation
» Vector Application Icon for Android — A Complete Guide. | Roman Cinis | Sciencx | https://www.scien.cx/2021/08/16/vector-application-icon-for-android%e2%80%8a-%e2%80%8aa-complete-guide/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.