Android Question [B4X] B4XPages hamburger button?

agraham

Expert
Licensed User
Longtime User
I am impressed with B4XPages simplicity so far. I seem now, with v1.03, to do (almost) everything I can think of for now - with one exception!

I would like to replace the UpIndicator on the ActionBar with a hamburger button that I can use to open a B4XDrawer on that page. Betraying my total ignorance of things ActionBar related is there a JavaObject hack that would implement this?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are several ways to do it. Here is one implementation that should go in the page where you want to show the hamburger icon and assuming that you need the up key on other pages:
B4X:
Private Sub B4XPage_Appear
    Sleep(0) '<-- important.
    B4XPages.GetManager.ActionBar.RunMethod("setDisplayHomeAsUpEnabled", Array(True))
    Dim bd As BitmapDrawable
    bd.Initialize(xui.LoadBitmapResize(File.DirAssets, "hamburger.png", 32dip, 32dip, False)) 'better to load the image once and store it in a global variable.
    B4XPages.GetManager.ActionBar.RunMethod("setHomeAsUpIndicator", Array(bd))
End Sub

Private Sub B4XPage_Disappear
    B4XPages.GetManager.ActionBar.RunMethod("setHomeAsUpIndicator", Array(0))
End Sub

Clicking on the icon will raise the CloseRequest event. This means that it will behave the same as clicking on the back button. If it is problematic for you then add a flag in Activity_ActionBarHomeClick in the Main module.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Works OK if you already have B4XPagesManager.ShowUpIndicator = True globally but if it is False it leaves the UpIndicator functional on other pages. Disabling it in Disappear seems to fix it.
B4X:
Sub B4XPage_Disappear
    B4XPages.GetManager.ActionBar.RunMethod("setDisplayHomeAsUpEnabled", Array(False))
    B4XPages.GetManager.ActionBar.RunMethod("setHomeAsUpIndicator", Array(0))   
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…