I was following this tutorial https://www.b4x.com/android/forum/threads/appcompat-with-toolbar-minimal-example.79896/ and I was wondering if is there a way to show the overflow menu from code? [as simulating a click event]
Last edited:
I can confirm this is working fine as expected. Thank you! I was very close to this solution also, but not there yet!You can use this code: ...
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode= KeyCodes.KEYCODE_MENU Then
Dim jo As JavaObject=ToolBar
jo.RunMethod("showOverflowMenu",Null)
'ToolBar was renamed from ACToolBarLight1 in my case
Return True
End If
Return False
End Sub
Of course is showing, but on the bottom left part of the screen instead on the top right.The menu will open automatically when the user clicks on the menu button.
Let's just say this is what I like best (and not let anyone including google decide what is standard and non standard - in this case at least).Why is this code needed at all?
This is from manifest editor:What is the value of targetSdkVersion in the manifest editor?
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21"/>
There is no menu coming from the bottom. I did apply the code you reccomend. Without it, there will be a normal menu on the bottom left corner... The overflow menu is some time showing/many times not showing, only on the upper right corner. But with issues describe above. Do you still need pictures?Can you post a screenshot of the menu coming from the bottom of the screen?
Sub ShowOverflow
Dim jo AsJavaObject=ToolBar
jo.RunMethod("showOverflowMenu",Null) 'ToolBar was renamed from ACToolBarLight1 in my case
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode= KeyCodes.KEYCODE_MENU Then
CallSubDelayed(Me,"ShowOverflow")
Return True
End If
Return False
End Sub
Sub Activity_KeyUp (KeyCode As Int) As Boolean
If KeyCode= KeyCodes.KEYCODE_MENU Then
CallSubDelayed(Me,"ShowOverflow") ' In fact it shouldn't be needed anymore, but I find it cleaner.
Return True
End If
Return False
End Sub
Public Sub ShowOverflowMenu(ToolBarLight As ACToolBarLight, ToolBarDark As ACToolBarDark) As Boolean
Try
Dim jo As JavaObject
If ToolBarLight.IsInitialized Then jo=ToolBarLight
If ToolBarDark.IsInitialized Then jo=ToolBarDark
jo.RunMethod("showOverflowMenu",Null)
Return True
Catch
MsgboxAsync ("Eroare Tools.ShowOverflowMenu: " & LastException.Message,"")
Return False
End Try
End Sub
Sub Activity_KeyUp (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode= KeyCodes.KEYCODE_MENU Then
Tools.ShowOverflowMenu(ToolBar,Null)'second parameter is if theme is dark...make first null
Return True
End If
Return False
End Sub