Android Code Snippet Adaptive Icons - simple instructions and tips

Erel

Administrator
Staff member
Licensed 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
 

yiankos1

Active Member
Licensed User
I use this very simple tool

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

oparra

Well-Known Member
Licensed 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>
)
 
Top