B4J Question activate/deactivate tryMenuItem of an SystemTray menu [SOLVED]


Well-Known Member
Licensed User
Longtime User
Hi all, it's possible to activate/deactivate a tryMenuItem ?

Thanks in advice


B4X founder
Staff member
Licensed User
Longtime User
You mean SystemTray.

You can use this code:
Sub TrayIconSetEnabled(Index As Int, Enabled As Boolean)
    Dim jo As JavaObject = Tray 'Tray is the SystemTray object
    Dim TrayIconS() As Object = jo.GetFieldJO("st").RunMethod("getTrayIcons", Null)
    Dim ti As JavaObject = TrayIconS(0) 'assuming that there is a single icon
    Dim popup As JavaObject = ti.RunMethod("getPopupMenu", Null)
    popup.RunMethodJO("getItem", Array(Index)).RunMethod("setEnabled", Array(Enabled))
End Sub
Upvote 0