Android Code Snippet Adaptive Icons - simple instructions and tips

All apps should have an adaptive icon. If you are not familiar with these icons then start here: Adaptive Icons

Instruction steps:
  1. Create a new folder in the root project folder named icon.
  2. Create two folders inside that folder with the following files:
    1. mipmap:
      1. ic_launcher.png - non-adaptive icon for Android 7- devices. There is no specific size. Should be 128x128 or or more.
      2. background.png - 108x108 - the solid background layer.
      3. foreground.png - 108x108 - the foreground layer.
    2. mipmap-xxxhdpi (high resolution images):
      1. background.png - 432x432 - solid background layer
      2. foreground.png - 432x432 - foreground layer
  3. Add to main module:
    B4X:
    #AdditionalRes: ../icon
  4. Add to manifest editor:
    B4X:
    SetApplicationAttribute(android:icon, "@mipmap/ic_launcher")
    CreateResource(mipmap-anydpi-v26, ic_launcher.xml,
    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/background"/>
    <foreground android:drawable="@mipmap/foreground"/>
    </adaptive-icon>
    )
No need to set any file to be read-only.

Example: https://github.com/AnywhereSoftware/B4X-Pleroma/tree/master/B4A
 
Last edited:

yiankos1

Well-Known Member
Licensed User
Longtime User
I use this very simple tool

Do you follow site's instructions or Erel's, in order to be compatible at b4a?
 

TILogistic

Expert
Licensed User
Longtime User
Do you follow site's instructions or Erel's, in order to be compatible at b4a?
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="29"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
'SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.

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

CreateResource(mipmap-anydpi-v26, ic_launcher.xml,
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@color/ic_launcher_background" />
    <foreground android:drawable="@mipmap/ic_launcher_foreground" />
</adaptive-icon>
)
 

asales

Expert
Licensed User
Longtime User
Thanks for this tutorial. Very simple. Now I have adaptive icons in my apps.
 

SMOOTSARA

Active Member
Licensed User
Longtime User
All app should have an adaptive icon. If you are not familiar with these icons then start here: Adaptive Icons

Instruction steps:
  1. Create a new folder in the root project folder named icon.
  2. Create two folders inside that folder with the following files:
    1. mipmap:
      1. ic_launcher.png - non-adaptive icon for Android 7- devices. There is no specific size. Should be 128x128 or or more.
      2. background.png - 108x108 - the solid background layer.
      3. foreground.png - 108x108 - the foreground layer.
    2. mipmap-xxxhdpi (high resolution images):
      1. background.png - 432x432 - solid background layer
      2. foreground.png - 432x432 - foreground layer
  3. Add to main module:
    B4X:
    #AdditionalRes: ../icon
  4. Add to manifest editor:
    B4X:
    SetApplicationAttribute(android:icon, "@mipmap/ic_launcher")
    CreateResource(mipmap-anydpi-v26, ic_launcher.xml,
    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/background"/>
    <foreground android:drawable="@mipmap/foreground"/>
    </adaptive-icon>
    )
No need to set any file to be read-only.

Example: https://github.com/AnywhereSoftware/B4X-Pleroma/tree/master/B4A




Hello
After this method, do we have to put the main icon of the "==>Objects\res\drawable" and set file to be read-only.
Or it is no longer necessary?
thankyou
 

Alessandro71

Well-Known Member
Licensed User
Longtime User
does this also applies to the notification icons also?
currently I use this code
B4X:
        Dim n As Notification
        n.Initialize
        'put file in res\drawable and set read-only
        n.Icon = "notification"
can I move the notification.png file to the icon folder, with no read-only attribute?
 

SMOOTSARA

Active Member
Licensed User
Longtime User
All app should have an adaptive icon. If you are not familiar with these icons then start here: Adaptive Icons

Instruction steps:
  1. Create a new folder in the root project folder named icon.
  2. Create two folders inside that folder with the following files:
    1. mipmap:
      1. ic_launcher.png - non-adaptive icon for Android 7- devices. There is no specific size. Should be 128x128 or or more.
      2. background.png - 108x108 - the solid background layer.
      3. foreground.png - 108x108 - the foreground layer.
    2. mipmap-xxxhdpi (high resolution images):
      1. background.png - 432x432 - solid background layer
      2. foreground.png - 432x432 - foreground layer
  3. Add to main module:
    B4X:
    #AdditionalRes: ../icon
  4. Add to manifest editor:
    B4X:
    SetApplicationAttribute(android:icon, "@mipmap/ic_launcher")
    CreateResource(mipmap-anydpi-v26, ic_launcher.xml,
    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/background"/>
    <foreground android:drawable="@mipmap/foreground"/>
    </adaptive-icon>
    )
No need to set any file to be read-only.

Example: https://github.com/AnywhereSoftware/B4X-Pleroma/tree/master/B4A



Hi

I want to have an icon with a clear background (transparent)
This means that the ( background.png ) file is a transparent file

But in the program it shows the background in black

What is the cause of this issue?
 

MrKim

Well-Known Member
Licensed User
Longtime User
Do you follow site's instructions or Erel's, in order to be compatible at b4a?
I used this tool but it created a zip file with a directory structure with a lot more files.
1609560585479.png

I found a 108 foreground icon in mipmap-mdpi and a 432 in mipmap-xxxhdpi.

But in both cases the the background file was smaller but it seemed to work. At least in testing on my one device.

I was wondering which files you used?
 

MrKim

Well-Known Member
Licensed User
Longtime User
All apps should have an adaptive icon. If you are not familiar with these icons then start here: Adaptive Icons

Instruction steps:
  1. Create a new folder in the root project folder named icon.
  2. Create two folders inside that folder with the following files:
    1. mipmap:
      1. ic_launcher.png - non-adaptive icon for Android 7- devices. There is no specific size. Should be 128x128 or or more.
      2. background.png - 108x108 - the solid background layer.
      3. foreground.png - 108x108 - the foreground layer.
    2. mipmap-xxxhdpi (high resolution images):
      1. background.png - 432x432 - solid background layer
      2. foreground.png - 432x432 - foreground layer
  3. Add to main module:
    B4X:
    #AdditionalRes: ../icon
  4. Add to manifest editor:
    B4X:
    SetApplicationAttribute(android:icon, "@mipmap/ic_launcher")
    CreateResource(mipmap-anydpi-v26, ic_launcher.xml,
    <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@mipmap/background"/>
    <foreground android:drawable="@mipmap/foreground"/>
    </adaptive-icon>
    )
No need to set any file to be read-only.

Example: https://github.com/AnywhereSoftware/B4X-Pleroma/tree/master/B4A
I missed this:
B4X:
#AdditionalRes: ../icon
And couldn't figure out where it was getting the icons
Finally figured out it was using the ones in Objects\res\mipmap and Objects\res\mipmap-anydpi-v26
What do we do with these files?
 
Top