Android Question [B4X] B4XPages - Main menu

agraham

Expert
Licensed User
Longtime User
We may be trying to run before we can walk here!

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?
 

agraham

Expert
Licensed User
Longtime User
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.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
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.
If your app is using AppCompat (and its Editable Menu) you can change the Menu. Not sure how it works inside the new "Pages-Feature" though.

 
Upvote 0

agraham

Expert
Licensed User
Longtime User
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")
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
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.
You mentioned jadx, but have you heard of JEB from PNF Software?
 
Upvote 0

wes58

Active Member
Licensed User
Longtime User
$1,080 per year :eek: That's way out of my price range.
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.
 
Upvote 0

cimperia

Active Member
Licensed User
Longtime User
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.
 
Upvote 0

Acuario

Active Member
Licensed User
Longtime User
@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.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
You should always start a new thread ... You could include a link and reference to the first post in your question.

B4XPages Ver 1.03 with support for menus.
 
Upvote 0

Similar Threads

Top