Android Question multi-res support for toolbar icons?

Dave O

Well-Known Member
Licensed User
Longtime User
Hi all,

What's the "correct" B4A/Android way to support multiple resolutions for toolbar icons?

So far in my apps, I've used this simplistic method to do toolbar icons:
- Get a 24dip icon from a site like materialdesignicons.com.
- Use a paint program to create a 48dip bitmap with the 24dip icon centered.
- Create a "pressed" version by adding a transparent grey background.
- Create the button in the B4A designer, and point the Enabled and Pressed drawable properties to the respective bitmap files.

That works (although it seems very manual for such a common task). However, I'd like to start doing it the "correct" way, which I assume is using multi-resolution resources (e.g. drawable-mdpi, drawable-hdpi, etc.).

Searching the B4A forums, I don't see any way to reference a resource from the designer, so the best bet seems to be to do it in code using the AndroidResources library. Is this the easiest way?

In a perfect world, I could add a button using the designer, choose an icon visually from a gallery, and it would handle the multi-res stuff and the various StateListDrawable states for me. That would definitely fit the idea of a RAD tool. :)

Cheers!
 

Dave O

Well-Known Member
Licensed User
Longtime User
This is the correct way.

Sorry, do you mean the way I'm doing it now, loading bitmaps in the designer? Doesn't that mean I'm only providing a single-resolution icon?

Or do you mean using AndroidResources in code?
 
Upvote 0
Top