Android Question Hiding menu created during runtime with AppCompat

kostefar

Active Member
Licensed User
Longtime User
Dear All,

I have the 3-dot menu set in my actionbar with

B4X:
ACToolBarLight1.InitMenuListener

Sub Activity_CreateMenu(Menu As ACMenu)
    Menu.Clear
  
    Menu.Add(0, 0, "Blahblah", Null)
    Menu.Add(1, 0, "Blahblahblah", Null)
  
End Sub

This is something I want to appear when the actionbar shows only sometimes. How can I hide the menu and unhide it again?

I´ve searched the forum, but wasn´t sure if the question was exactly the same, so please bare with me if that´s indeed the case.

Thanks in advance!
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

kostefar

Active Member
Licensed User
Longtime User
Hi again,

Now you can call me lazy or a patient digger for simplicity or none of those. I could see stuff would be working with what you suggested but I wanted to keep changes to as few as possible: The more you change, the more can go wrong later.
So I suddenly figured out how simple it can be done.

In the globals, put something like:

B4X:
Dim menuon as boolean
Private ACToolBarLight1 As ACToolBarLight

Then set the createmenu event up like this:

B4X:
Sub Activity_CreateMenu(Menu As ACMenu)
    Menu.Clear
    If menuon = True Then     
    Menu.Add(0, 0, "w", Null)
    Menu.Add(1, 0, "x", Null)
    Menu.Add(2, 0, "y", Null)
    Menu.Add(3, 0, "z", Null)
    End If
End Sub

Then whenever you want the menu to appear, put this in your code:

B4X:
menuonfirst = True
ACToolBarLight1.InitMenuListener

And when you want it to disappear:

B4X:
menuonfirst = False
ACToolBarLight1.InitMenuListener

You could of course set things up with more choices than just the menu on and off, but for me this was all I needed.

Edit: You´ll need to load a new activity with the Actoolbarlight in it for this to work. The listener won´t fire if you don´t do that.
 
Last edited:
Upvote 0
Top