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
Longtime 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.
 

TILogistic

Expert
Licensed User
Longtime 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: 283
Last edited:

Vinians2006

Active Member
Licensed User
Longtime 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: 161

Vinians2006

Active Member
Licensed User
Longtime 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
 

TILogistic

Expert
Licensed User
Longtime 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.
 

johnaaronrose

Active Member
Licensed User
Longtime User
Apologies for my last incorrect post: it's obvious what to do if I had not had a senile moment! I just noticed the Download button on the web site. I've clicked on the Android instruction. But when I click on the Download button, it gives 2 options: one for iOS with Adaptive icon button & one with iOS with Legacy button only. I clicked on the Adaptive button and I noticed that the ic_launcher zip contains a folder for iOS and a folder for Android.

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 hey 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?
 
Last edited:
Top