Android Tutorial Implementing Launcher Icons using MipMap

The Launcher icon always shows as 48x48 dip, but when translated into pixels on screens with different resolutions, this can become 48, 72, 96, 144 or even 192 pixels square. You should ideally provide versions of your icon in all these sizes, distributed in folders whose names include the word mipmap. Luckily this is very easy to do. When your app runs, Android can then check the characteristics of the device screen and load the appropriate density-specific assets for your app. This will give your app a professional appearance on all devices irrespective of the screen resolution.

MipMap is very easy to implement. You do not need to use [Project > Choose Icon]. Instead, you need to generate a single master image for your icon. Since you will also need an image 512x512 pixels in 32-bit PNG format for Google Play, you might decide to start your artwork in that size and then resize it to produce the smaller format images. But it might be better to start with an image of 864x864 pixels, which can be accurately be downsized to the sizes needed by mipmap.

Convert your icon to images with sizes of 48, 72, 96, 144 and 192 pixels square ready for mipmap using the on-line Launcher Icon Generator. This not only generates the images but puts them into the correct folders. The zip file which this creates will contain a folder called \res containing other folders called \mipmap-hdpi, \mipmap-mdpi and so on.

Each of these folders contains an image with the same name but with different sizes. They can have any name, but the commonest name is ic_launcher.png

You need to copy these folders to your project’s Objects\res folder, so you have \Objects\res\mipmap-hdpi etc. Once copied, you must set these folders and files to be read only by selecting all the folders, right-clicking and selecting Properties from the pop-up menu, then checking the Read-only option.

The final step is to let Android know where to look for your icons by editing the Manifest. Edit the line

B4X:
SetApplicationAttribute(android:icon, "@drawable/icon")

and change it to

B4X:
SetApplicationAttribute(android:icon, "@mipmap/ic_launcher")

Where the word ic_launcher matches the names of your icons. You do not need to specify the file extension.

Note: This is an extract from the forthcoming book B4A, which has been extensively revised from our earlier book Basic4Android and covers B4A up to 4.30

B4A-2nd-Ed-Front-Cover-1000-244x300.jpg
 

johnaaronrose

Active Member
Licensed User
Longtime User
PhilipBrown How does Android know which image to use? I'm wondering if you have to code in B4A in order to achieve this.
 

johnaaronrose

Active Member
Licensed User
Longtime User
Thanks for that. All a little confusing. In https://www.b4x.com/android/forum/t...ple-instructions-and-tips.123843/page-2#posts post #24 gives a different way of doing "Adaptive Icons". This post refers to a web site https://easyappicon.com which generates all the images from one icon (at least 128x128 pixels) and specifies changes to the Main module & the manifest. The generated images (in their sub-folders) look Ok. But the changes in the manifest are not reflected in the example project! I have attached a file showing the manifest in the example project together with a zip file of that project as well as the changes. If the changes are correct where do they go in the standard manifest?

Would not doing the Adaptive Icons procedure prevent a search (from a phone) on Google Play Store from finding an app even though it's gone live on the Play Store?
 

Attachments

  • AdaptiveIconsManifestChanges.txt
    310 bytes · Views: 190
  • Adaptive Icons.zip
    184.3 KB · Views: 201
  • AndroidManifest.xml
    1.2 KB · Views: 180
Last edited:
Top