Day43 of #100DaysOfCode
Hii folks 🙌
Today I learned to add a launcher icon to the android app.
Unit 2: Layouts
Pathway 2: Get user input in an app — Part 2
Source: https://developer.android.com/courses/android-basics-kotlin/course
We will first start by either creating a new project or the previous project on which we’re already working.
So, firstly we will navigate to mipmap
folders where we will put the launcher icon assets for our Android app.
mdpi
, hdpi
, xhdpi
, etc.. are density qualifiers that we can append onto the name of a resource directory (like mipmap
) to indicate that these are resources for devices of a certain screen density. Here's a list of density qualifiers on Android:
mdpi
- resources for medium-density screens (~160 dpi)hdpi
- resources for high-density screens (~240 dpi)xhdpi
- resources for extra-high-density screens (~320 dpi)xxhdpi
- resources for extra-extra-high-density screens (~480dpi)xxxhdpi
- resources for extra-extra-extra-high-density screens (~640dpi)nodpi
- resources that are not meant to be scaled, regardless of the screen's pixel densityanydpi
- resources that scale to any density
In the ic_launcher.xml
file of mipmap-anydpi-v26, we will add the following code:
<?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/ic_launcher_foreground" />
</adaptive-icon>
The <adaptive-icon>
element is used to declare the <background>
and <foreground>
layers of the app icon by providing resource drawable for each.
Then we will add the new assets to our app and will change the launcher icon.
And now the icon looks like this
Today I Learned:
- We should place app icon files in the
mipmap
resource directories. - We should also provide different versions of an app icon bitmap image in each density bucket (
mdpi
,hdpi
,xhdpi
,xxhdpi
,xxxhdpi
) for backward compatibility with older versions of Android. - Vector drawables are Android’s implementation of vector graphics. They are defined in XML as a set of points, lines, and curves along with associated color information. Vector drawables can be scaled for any density without loss of quality.
- We can use Image Asset Studio in Android Studio to create a legacy and adaptive icons for our app.
That is all for Day43 ✅
Thanks for reading, See you tomorrow!