Hi, I have a menubar with a few child menus. I need to implement clickable item on the toolbar - this is so the user doesnt have to click the menu to activate a tool.
I can change the text out for an image which is fine but there doesnt seem to be an event for clicking the menu parent item. I have found some code that will add an event using the "OnShowing" event but since this item has no children the event never fires - there is no OnMouseClick on the menu as far as I can see in the JavaDocs.
may be you already have figured the label part, i think that one is a nice solution and very easy to implement
B4X:
Dim menu As MenuBar
Dim jo As JavaObject = menu.Menus.Get(0)
Dim lbl As Label
lbl.Initialize("yourLabel")
lbl.Text = "lol"
jo.RunMethod("setGraphic",Array(lbl))
may be you already have figured the label part, i think that one is a nice solution and very easy to implement
B4X:
Dim menu As MenuBar
Dim jo As JavaObject = menu.Menus.Get(0)
Dim lbl As Label
lbl.Initialize("yourLabel")
lbl.Text = "lol"
jo.RunMethod("setGraphic",Array(lbl))
Full code below. It swaps an existing "title" menu item with a label with a font awesome icon that has a click event handler!
NOTE: to make the menu more "button like" it has no children; {Text: "replace-me",Children:[]}
B4X:
Sub ReplaceMenuItem
Dim jo As JavaObject = MenuBar1.Menus.Get(4)
Dim lbl As Label
lbl.Initialize("yourLabel")
lbl.Text = Chr(0xf0c5)
lbl.Font = fx.CreateFontAwesome(18)
jo.RunMethod("setText",Array("")) 'Replace existing text (if you have set some)
jo.RunMethod("setGraphic",Array(lbl))
End Sub
Sub yourLabel_MouseClicked (EventData As MouseEvent)
Log("Hello")
End Sub