Android Question Bottom Menu problems

pliroforikos

Active Member
Licensed User
Hello
I am uploading a class with bottom menu that i have create . It works fine until now.
I call it from main Activity in order to stay still as b4xpages changes.
So far so good but... I can't call methods of menu from b4xPages cos i don't know how to call them from main :mad: Can you please help me?


1643571869756.png


Main Activity:
Sub Activity_Create(FirstTime As Boolean)
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
    
    'Menu Creation
    Dim mnPages, mnText, mnIcons As List
    mnPages.Initialize
    mnPages.AddAll(Array As String("MainPage", "pgPage1", "pgPage2"))
    mnText.Initialize
    mnText.AddAll(Array As String("Main Page", "Page1", "Page2"))
    mnIcons.Initialize
    'The menu supports only materialdesignicons-webfont.ttf
    'use https://www.b4x.com/android/forum/threads/b4x-materialicons-web-font-chooser.103985/#content
    'to get appropriate icon codes
    mnIcons.AddAll(Array As Long(0xf104, 0xf14f, 0xf0ee))

    btmMenu.Initialize(Activity, mnPages)
    btmMenu.createMenu
    btmMenu.texts(mnText)
    btmMenu.icons(mnIcons)
    btmMenu.setLinesVisible(False)
End Sub

btmMenu Class:
Sub Class_Globals
    Public xui As XUI
    Public Root As B4XView
    
    Private Btn1Icon As Label
    Private Btn1Lbl As Label
    Private Btn2Icon As Label
    Private Btn2Lbl As Label
    Private Btn3Icon As Label
    Private Btn3Lbl As Label
    Private HLine1 As B4XView
    Private HLine2 As B4XView
    Private BtmMenu As B4XView
    Private Btn1 As Panel
    Private Btn2 As Panel
    Private Btn3 As Panel
    Private mnPages As List    ' A list of string with pages names
    
    'Public
    Public focusedIconColor As Long = 0xFFFFFFFF
    Public iconsColor As Long = 0xff8bc0eb
    Public focusedTextColor As Long = 0xFFFFFFFF
    Public textColor As Long  = 0xFF8bc0eb
    Public LinesColors As Long = 0xFF3490dc
    Public BtmMenuColor As Long =  0xFF1D3557
End Sub

'The menu supports only materialdesignicons-webfont.ttf
'use https://www.b4x.com/android/forum/threads/b4x-materialicons-web-font-chooser.103985/#content
'to get appropriate icon codes
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(Parent As B4XView, pages As List)
    Root = Parent
    mnPages = pages
End Sub

Public Sub createMenu
    Dim pan As Panel
    pan.Initialize("")
    Root.AddView(pan, 0, 0, 100%x, 100%y)
    pan.LoadLayout("frmBtmMenu")
    BtmMenu.Color = BtmMenuColor
    HLine1.Color = LinesColors
    HLine2.Color = LinesColors
    Btn1Icon.TextColor= focusedIconColor
    Btn1Lbl.TextColor = focusedTextColor
    Btn2Icon.TextColor = iconsColor
    Btn2Lbl.TextColor = textColor
    Btn3Icon.TextColor = iconsColor
    Btn3Lbl.TextColor = textColor
    Btn1Lbl.Text = "Main"
    Btn2Lbl.Text = "Page 1"
    Btn3Lbl.Text = "Page 2"
End Sub

Public Sub setIconsFocus(choosed As Int)
    If choosed = 0 Then
        Btn1Icon.TextColor= focusedIconColor
        Btn1Lbl.TextColor = focusedTextColor
        Btn2Icon.TextColor = iconsColor
        Btn2Lbl.TextColor = textColor
        Btn3Icon.TextColor = iconsColor
        Btn3Lbl.TextColor = textColor
    else if choosed = 1 Then
        Btn1Icon.TextColor = iconsColor
        Btn1Lbl.TextColor = textColor
        Btn2Icon.TextColor = focusedIconColor
        Btn2Lbl.TextColor = focusedTextColor
        Btn3Icon.TextColor = iconsColor
        Btn3Lbl.TextColor = textColor
    else if choosed = 2 Then
        Btn1Icon.TextColor = iconsColor
        Btn1Lbl.TextColor = textColor
        Btn2Icon.TextColor = iconsColor
        Btn2Lbl.TextColor = textColor
        Btn3Icon.TextColor = focusedIconColor
        Btn3Lbl.TextColor = focusedTextColor
    End If
End Sub

Public Sub texts(l As List)
    Btn1Lbl.Text = l.Get(0)
    Btn2Lbl.Text = l.Get(1)
    Btn3Lbl.Text = l.Get(2)
End Sub

Public Sub icons(l As List)
    Btn1Icon.Text = Chr(l.Get(0))
    Btn2Icon.Text = Chr(l.Get(1))
    Btn3Icon.Text = Chr(l.Get(2))
End Sub

Public Sub setLinesColors(c As Long)
    HLine1.Color = c
    HLine2.Color = c
End Sub

Public Sub setLinesVisible(v As Boolean)
    HLine1.Visible = v
    HLine2.Visible = v
End Sub

Public Sub disableMenu
    Btn1.Enabled = False
    Btn2.Enabled = False
    Btn3.Enabled = False
End Sub

Public Sub enableMenu
    Btn1.Enabled = True
    Btn2.Enabled = True
    Btn3.Enabled = True
End Sub

'Call item menu
'Every menu PAnel has the same mnItems Event name with different tag 0, 1, 2
Private Sub mnItems_Click()
    Dim mn As B4XView = Sender
    B4XPages.ShowPageAndRemovePreviousPages(mnPages.Get(mn.tag))
    setIconsFocus(mn.tag)
End Sub
 

Attachments

  • Project.zip
    271.1 KB · Views: 112

pliroforikos

Active Member
Licensed User
Thank you. But like this i have to use it in every b4xpage. And there is a small gap when pages change to menu view.
Somewhere Erel propose a a lution in Main activity but i cant find it right now.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
?
Main:
Add B4XPages.MainPage.bm = btmMenu
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
    
    'Menu Creation
    Dim mnPages, mnText, mnIcons As List
    mnPages.Initialize
    mnPages.AddAll(Array As String("MainPage", "pgPage1", "pgPage2"))
    mnText.Initialize
    mnText.AddAll(Array As String("Main Page", "Page1", "Page2"))
    mnIcons.Initialize
    'The menu supports only materialdesignicons-webfont.ttf
    'use https://www.b4x.com/android/forum/threads/b4x-materialicons-web-font-chooser.103985/#content
    'to get appropriate icon codes
    mnIcons.AddAll(Array As Long(0xf104, 0xf14f, 0xf0ee))

    btmMenu.Initialize(Activity, mnPages)
    btmMenu.createMenu
    btmMenu.texts(mnText)
    btmMenu.icons(mnIcons)
    btmMenu.setLinesVisible(False)
    
    B4XPages.MainPage.bm = btmMenu
End Sub

BAXMainPage
Add Public bm As BottomMenu
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public pgPage1 As B4XPagePg1
    Public pgPage2 As B4XPagePg2
    Public bm As BottomMenu
End Sub


Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    pgPage1.Initialize
    B4XPages.AddPage("pgPage1", pgPage1)
    
    pgPage2.Initialize
    B4XPages.AddPage("pgPage2", pgPage2)
    
End Sub

Private Sub B4XPage_Appear
    bm.disableMenu
    Sleep(5000)
    bm.enableMenu
End Sub
 
Upvote 0
Top