For the few apps I write for Android I adopt a very clean (in my opinion ) aesthetic using only the main menu on the title bar of an activity. This sort of mimics a desktop app with just a main menu bar. I don't like animations and fancy colored thingies etc. Using the main menu in a B4XPages app means that each page defaults to having the same main menu items and the menu events are raised in Main. I have been trying to customise this for each B4XPage. I have tried adding menu items within each page using this in B4XPage_Create.
B4X:
Dim act As Activity = B4XPages.GetNativeParent(Me)
act.AddMenuItem("Fred", "Menu")
' or
Dim act As Activity = Root1
act.AddMenuItem("Fred", "Menu")
but this only works for B4XMainPage as other pages do not seem to have Main as their parent or root. So firstly is there a way to get a reference to Main in every B4XPage so each page can set its own menu items in their own B4XPage_Create?
Having added the menu items I think I can mange to call into each B4XPage as required from the menu event Subs in main. However I now need a mechanism to remove or hide the unwanted items according to which page is displayed. I don't think the menu items can be removed once added but I think they can be individually enabled/disabled and hidden if required. So secondly is there a way using Reflection or JavaObject to access the menu items to manipulate them.
I've tried poking around to see how the menu is implemented in B4A but have come up against a blank wall with B4AActivity.addMenuItem whose concrete implementation I can't find. Should I give up now or later?
I've finally found how a B4A Activity creates its options menu and am giving up at this point as there doesn't appear to be an accessible list of the actual MenuItem objects.
You might be interested to know of a program called jadx which can look inside an apk and show you the Dalvik code decompiled back to Java.
Jadx is a recent discovery. I have used JD-GUI for many years to poke around inside jar files.
I've finally found how a B4A Activity creates its options menu and am giving up at this point as there doesn't appear to be an accessible list of the actual MenuItem objects.
Note: You should use B4A 6.0 or above for this tutorial. With the ACToolBar(Light|Dark) object we can get access to the Menu object of the activity. This opens the possibility for modifyable menus and some other advanced menu features. Basics With the ToolBar.Menu property we have access to...
Until someone comes up with a better idea, for the time being I am using B4XDrawer to provide individualised menus for each page while I am playing with B4XPages.
Two things to note :-
1) Use Root to Initialise the Drawer instead of Activity Drawer.Initialize(Me, "Drawer", Root, 200dip)
2) Load the layout into Drawer.CenterPanel and not Root Drawer.CenterPanel.LoadLayout("Page3")
I've finally found how a B4A Activity creates its options menu and am giving up at this point as there doesn't appear to be an accessible list of the actual MenuItem objects.
You might be interested to know of a program called jadx which can look inside an apk and show you the Dalvik code decompiled back to Java.
Jadx is a recent discovery. I have used JD-GUI for many years to poke around inside jar files.
Sure, if you only use it a couple of times a year, you are not going to spend that kind of money. But nowadays, you can find almost anything on the internet.
You could hardly beat bytecodeviewer. It's free, open source and does a great job. It includes/embeds 6 decompilers (JADX is one of them) and you can edit the APK, should you want to, and more.
@agraham How did you manage to get the menu on B4XMainPage? I have tried adding the code you pasted in B4XPage_Created but I get nothing.. I only need the menu on the main page.
B4XPages is a library that serves two purposes: 1. Make it simple to develop B4A apps by solving almost all of the challenges involved with Android complex activities life cycle. B4XPages makes B4A behave more similar to B4J and B4i where the new "B4XPage" element is a regular object that is...