Android Tutorial Implementing Launcher Icons using MipMap

Discussion in 'Tutorials & Examples' started by PhilipBrown, Mar 7, 2015.

  1. PhilipBrown

    PhilipBrown Active Member Licensed User

    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

    Code:
    SetApplicationAttribute(android:icon, "@drawable/icon")
    and change it to

    Code:
    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

    [​IMG]
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice