I tried a quick hack to see if I could get one of the images
B4X:
Dim Icon2 As Bitmap
Dim ph As Phone
Dim can As Canvas
Dim r As Rect
can.Initialize2 (icon2)
r.Initialize (0,0,47,47)
icon2.InitializeMutable(48,48)'just guessed the size for now
can.DrawDrawable ( ph.GetResourceDrawable ( 17301515) ,r)'Star
This loaded the "star" image into icon2 ready to use in menus etc. Just need to get my head around the sizing now.
Dim Icon2 As Bitmap
Dim ph As Phone
Dim can As Canvas
Dim rc As Rect
icon2.InitializeMutable(48,48)
can.Initialize2(icon2)
rc.Initialize (0,0,47,47)
icon2.InitializeMutable(48,48)
can.DrawDrawable(ph.GetResourceDrawable(17301581), rc) ''ic_menu_rotate
Activity.AddMenuItem2("Kennwort ändern", "mnuChangePasswd", Icon2 )
My menu does not contain a bitmap.
where is the mistake?
May be a problem with the hard coded sizes I put in (48 x 48), thats why I called it a hack.
To be a fully working solution I need to understand the sizing of icons - I don't at the moment.
Good to see another hack that works, but be aware guys that this may not work across devices with different resolutions and pixel densities. Maybe a real expert will drop by soon...............
The simplest way is to convert the Drawable to a BitmapDrawable:
B4X:
Dim bd As BitmapDrawable
bd = ph.GetResourceDrawable(17301581)
Activity.AddMenuItem2("Kennwort ändern", "mnuChangePasswd", bd.Bitmap )
This will fail for resources that are not BitmapDrawable (like a color resource).
@Fillipo, it took me awhile to understand why your code doesn't work. The reason is that you initialize icon2 twice. The second initialize call is not necessary. It creates a new bitmap which is different than the one you are drawing on.