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:

Vinians2006

Active Member
Licensed User
I will wait for this resource to be added to Basic4Android because I tryed a lot but my program crash, so I ended up with simple "Choose Icon" on the menu that works fine.
 

oparra

Well-Known Member
Licensed User
1.- Download.

1609891126036.png


2. Unzip and find the android directory.

1609891921998.png


1609891253562.png


3. Add the resource directory where the icons are in your project.

Note: rename android directory to icon

1609891355031.png


4. Add the directory where the icons are to your project.

1609891470785.png


4. Add the following to the manifest.

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>
)

If you want to upload your own custom icon

1.- Choose file

1609892513930.png



And proceed with the steps mentioned above.

See the loaded demo

Regards.
 

Attachments

  • Adaptive Icons.zip
    184.3 KB · Views: 146
Last edited:

Vinians2006

Active Member
Licensed User
1.- Download.

View attachment 105531

2. Unzip and find the android directory.

View attachment 105535

View attachment 105532

3. Add the resource directory where the icons are in your project.

Note: rename android directory to icon

View attachment 105533

4. Add the directory where the icons are to your project.

View attachment 105534

4. Add the following to the manifest.



If you want to upload your own custom icon

1.- Choose file

View attachment 105536


And proceed with the steps mentioned above.

See the loaded demo

Regards.
Friend your explanation is clear, but the icon do not appears and the program closes before open the main actitvity. I dont know what is wrong, I tryed everything.
Please, can you help-me ? I attached the whole project in this post.
 

Attachments

  • NSMobile.zip
    110.7 KB · Views: 79

Vinians2006

Active Member
Licensed User
These should be used on your website and on Play Store.

View attachment 105587

Unzip the zip file and copy it to your project directory:

View attachment 105590

Your project is fine icon resource declarations.
the problem could be elsewhere..
Thank you but I think the zip I attached were not complete. Now this one is complete. Please, can you look at the files and see if you find any error ? Because Android dont even is able to load the apk. This is realted to icon because if I use that options to set an icon it works propertly.
The file is big to attach so here is the linke to google drive:
Link to download
 

oparra

Well-Known Member
Licensed User
Thank you but I think the zip I attached were not complete. Now this one is complete. Please, can you look at the files and see if you find any error ? Because Android dont even is able to load the apk. This is realted to icon because if I use that options to set an icon it works propertly.
The file is big to attach so here is the linke to google drive:
Link to download

Open a new post for inquiries.
 
Top