Default Andriod Icons

splatt

Active Member
Licensed User
Longtime User
Is there a way to access the internal icons defined here from within B4A?

This would enable completely authentic looking menus, when used with Activity.AddMenuItem2().
 

splatt

Active Member
Licensed User
Longtime User
Erel, as I've said in the past, the responsivness through this forum is second to none. Thank you.
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
Erel,

I've installed 1.3. How do I access the new icons?

p.s. The Bridge works superbly!
 
Upvote 0

splatt

Active Member
Licensed User
Longtime User
How would I include this call to provide the icon on Activity.AddMenuItem2()

Are these two compatible?
GetResourceDrawable (ResourceId As Int) As android.graphics.drawable.Drawable


AddMenuItem2 (Title As String, EventName As String, Bitmap As android.graphics.Bitmap)
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
I also cant see to how to consume the resource from GetResourceDrawable() so that I can use it in Activity.AddMenuItem2() for the image of the menu.

I am sure the is an answer :)

Jeremy
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0

jscoulter

Member
Licensed User
Longtime User
Interesting. When I run your code I get an error on

can.Initialize2 (Icon2)

saying the the :

Java.lang.RuntimeException" Object should first be initialized (BitMap)

This happens at runtime. I tried Icon2.initialize3(NULL) but it didnt like that.
Did you leave some thing out of your example at all?

Jeremy
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
Sorry, stupid cut and paste error.

the line "icon2.InitializeMutable(48,48)'just guessed the size for now"

should be before

"can.Initialize2 (Icon2)"
 
Upvote 0
D

Deleted member 103

Guest
Hi,

I have a problem!

This works correctly:
PHP:
Activity.Background = ph.GetResourceDrawable(17301581)

and that does not work:
PHP:
   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?
 

Attachments

  • Menu.jpg
    Menu.jpg
    18.4 KB · Views: 238
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
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...............
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.
 
Upvote 0
Top