Android Question update image in title bar menu item, is it possible at runtime.

jimseng

Active Member
Licensed User
Longtime User
I have added an image to my title bar and I want to change it at run time. I have had a guess but not had any success. Can someone show me the correct way to do it?
In B4XPage_Created:
B4X:
Public mi As B4AMenuItem = B4XPages.AddMenuItem(Me, "btnws")
    mi.AddToBar = True
    mi.Bitmap = xui.LoadBitmapResize(File.DirAssets, "gy.png", 24dip, 24dip, True)

for now as a test in B4XPage_MenuClick:
B4X:
If Tag = "btnws" Then
        Dim menus As List = B4XPages.GetManager.GetPageInfoFromRoot(Root).Parent.MenuItems
        For Each m As B4AMenuItem In menus
            If m.Tag = "btnws" Then
                Log("menu")
                m.Bitmap = xui.LoadBitmapResize(File.DirAssets, "gn.png", 24dip, 24dip, True)

            End If
'           
        Next
 

jimseng

Active Member
Licensed User
Longtime User
And so I found it (I think):
B4X:
Dim ctxt As JavaObject
                ctxt.InitializeContext
                ctxt.RunMethod("invalidateOptionsMenu", Null)
Am I going about this the right way?
 
Upvote 0
Top