How to use standard menu icons?

Inman

Well-Known Member
Licensed User
Longtime User
I have a menu in my application and currently I am using separate PNG files for each icon. I read that it is possible to use the inbuilt standard Android menu icons without including any extra assets. There is a discussion regarding this at the URL below, explaining how to achieve this in Java.

How to select standard Android menu icons? - Stack Overflow

I was wondering if this is possible in B4A.
 

kickaha

Well-Known Member
Licensed User
Longtime User
Snippet of code from one of my Activity_Create subs that displays inbuilt icons in the menu bar
B4X:
   Dim ph As Phone
   Dim bd As BitmapDrawable

   bd = ph.GetResourceDrawable(17301555)
   Activity.AddMenuItem2 ("Add Round", "AddRound", bd.Bitmap )   

   bd = ph.GetResourceDrawable(17301564)
   Activity.AddMenuItem2 ("Delete Round", "DelRound", bd.Bitmap )

   bd = ph.GetResourceDrawable(17301566)
   Activity.AddMenuItem2 ("Edit Round", "EditRound", bd.Bitmap )

   bd = ph.GetResourceDrawable(17301577)
   Activity.AddMenuItem2 ("Preferences", "Prefs", bd.Bitmap )

   bd = ph.GetResourceDrawable(17301568)
   Activity.AddMenuItem2 ("Help", "Help", bd.Bitmap )
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Google guidelines does not advice this because these resource ID's can change between versions. I would always include the PNG's.
 
Upvote 0

Rick in North Carolina

Member
Licensed User
Longtime User
Or is it that the sdk only guarantees the constant name for android java development... the integer behind it can change in the future?
Example: public static final int ic_menu_help
Constant Value: 17301568
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
... the integer behind it can change in the future?
Most unlikely. The name compiles to the integer value in the final code so if the API changed the integer values then existing compiled apps would break. It won't happen!
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
In its documentation Google says the values can change. Anyway, was just a remark and something I came across.

Always your own decision
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
In its documentation Google says the values can change. Anyway, was just a remark and something I came across.

Always your own decision

Do you have a web address for this as I would be interested to see it. This could potentially ruin all my menus if it is true!
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I have been trying out these built-in menu resources today. I seem to get most icons right. But 2 of them don't show up correctly:

ic_menu_refresh = 17301858
ic_menu_star = 17301859

When I try these constant values, I get some funny looking emoticons in return. I tested on Cyanogenmod 6.1 loaded Nexus One. On most Android discussions they ask you to use "ic_menu_refresh" instead of numeric value 17301858. I wonder if the value of ic_menu_refresh changes with different Android builds.

And correct me if I am wrong, I believe B4A needs numeric value and not the variable ic_menu_refresh.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I do not see these two values in the constants list: R.drawable | Android Developers

Oh...I wonder how these other developers manage to get hold of them. Particularly the refresh icon. It is pretty much there in most apps that use internet, including the default Gmail app.

I have the PNG file of the refresh icon which is what I am using now. It looks ok in Android 2.2 but from 2.3 the menu background changed from gray to black and now it looks bad.

Any idea how to add a refresh icon from builtin resource?


Thanks for the list. Unfortunately it lists only constant names and not their numerical values, which is what B4A needs. Oddly enough, ic_menu_refresh which is missing in the official documentation, is listed there.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Yes I checked the list. It doesn't have ic_menu_refresh while many apps including Gmail have a refresh icon in the menu. How?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I am not sure, but I think the ph.GetResourceDrawable results in a new permission request in the AndroidManifest.xml file - "Phone Calls - read phone state and identity". This could scare off some users and moreover you don't use the Phone object anymore; it is just for the icons.

Is it possible to avoid this permission request?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
Oh that's nice. I already set it as read only due to Admob permission and also since different activities have different orientations.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…