Android Question problem floating button inside toolbar

uniplan

Active Member
Licensed User
Longtime User
Hi, i'm trying to insert a floating buttons inside a single tab window,
but i receive this error when i load the loyout where i have the FloatingActionMenu ( p.LoadLayout("frmSocialWall"))

when i used tab, i load layout into panel, but in my case i need to load layout with floating button inside panel.
how i can solve it? Thank you

this is the error:
Error occurred on line: 299 (frmHome)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at jox.mobile.frmhome.afterFirstLayout(frmhome.java:102)
at jox.mobile.frmhome.access$000(frmhome.java:17)
at jox.mobile.frmhome$WaitForLayout.run(frmhome.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5938)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
... 20 more
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:2345)
at android.content.res.Resources.getDimension(Resources.java:1670)
at com.github.clans.fab.FloatingActionMenu.init(FloatingActionMenu.java:287)
at com.github.clans.fab.FloatingActionMenu.<init>(FloatingActionMenu.java:245)
at com.github.clans.fab.FloatingActionMenu.<init>(FloatingActionMenu.java:239)
at com.github.clans.fab.FloatingActionMenu.<init>(FloatingActionMenu.java:235)
at de.donmanfred.FloatingActionMenuWrapper._initialize(FloatingActionMenuWrapper.java:92)
... 24 more



B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#Extends: android.support.v7.app.AppCompatActivity


Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
   
    '-----------------------------------------------------
    'variabili per la gestione dell'action bar e dei menu
    '-----------------------------------------------------
    Private VP As AHViewPager
    Private PC As AHPageContainer
    Private TabLayout As DSTabLayout
    Private ToolBar As ACToolBarLight
   
    Private NavDrawer As DSNavigationDrawer
    Private ND As AHNavigationDrawer
    'Private NavDrawer As AHNavigationDrawer
    'Private Switch As ACSwitch
    Private HeaderLabel As Label
    '-----------------------------------------------------
    Private fam As FloatingActionMenu
    Private fabdesign1 As FloatingActionButton
    Private FABs As List
    '-----------------------------------------------------

    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private ImageViewPhotoProfile As ImageView
    Private FloatingActionMenu1 As FloatingActionMenu
    Private fabdesign1 As FloatingActionButton
End Sub

Sub Activity_Create(FirstTime As Boolean)

    If FirstTime = True Then
       
    End If
   
    NavDrawer.Initialize2("NavDrawer", Activity, NavDrawer.DefaultDrawerWidth, NavDrawer.GRAVITY_START)
    Activity.LoadLayout("frmHome")
    creazione_action_bar_e_menu
   

    ToolBar.InitMenuListener
   
    visualizza_info_menu
   
    carica_menu_float
End Sub

Sub carica_menu_float
    Activity.LoadLayout("Layout1")
    FABs.Initialize
    fam.ActivityHeight = 100%y
    fam.ActivityWidth = 100%x
    fabdesign1.ShowProgressBackground = False
    fabdesign1.ProgressWidth = 2dip
    fabdesign1.ProgressBackgroundColor = Colors.Red
    'fabdesign1.setProgress(90,True)
    fabdesign1.Indeterminate = True



    FloatingActionMenu1.Animated = True
    'fam.hideMenuButton(False)
    FloatingActionMenu1.IconAnimated = True
    'fam.ClosedOnTouchOutside = True
    'fam.AnimationDelayPerItem = 25
    'fam.MenuButtonLabelText = "Hallo B4A-World!"
    'fam.MenuButtonColorNormal = Colors.Yellow
    'fam.MenuButtonColorPressed = Colors.Blue
    'fam.Invalidate

    '
    ' I don´t know what the problem is, but the
    ' first 2 Fabs added will be ignored
    ' (they do not show in menu)
    '
    ' 1
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_accessibility"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Green
    btn1.ColorPressed = Colors.Magenta
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 1
    btn1.ShowShadow = True
    btn1.showButtonInMenu(True)
    btn1.LabelText = "Mööp 1"
    FloatingActionMenu1.addMenuButton(btn1)

    ' 2
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_accessibility"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Green
    btn1.ColorPressed = Colors.Magenta
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = True
    btn1.showButtonInMenu(True)
    btn1.LabelText = "Mööp 2"
    FloatingActionMenu1.addMenuButton(btn1)

    '
    ' From here the fab is added to the menu
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_accessibility"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Green
    btn1.ColorPressed = Colors.Magenta
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    'btn1.LabelVisibility = 1
    btn1.LabelText = "Hello B4A-World!"
    ' 3 (First)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_circle_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Magenta
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 0
    btn1.LabelText = "DonManfred is proud to present a new Menu"
    ' 4 (Second)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)


    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_box_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.LightGray
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 1
    btn1.LabelText = "a new Type of Menu"
    ' 5 (Third)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_balance_wallet_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Blue
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 1
    btn1.LabelText = "FloatingActionMenu"
    ' 6 (4th)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

   
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_balance_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Red
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 1
    btn1.LabelText = "*grins*"
   
    ' 5 (Third)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    FloatingActionMenu1.OpenDirection = 0
    FloatingActionMenu1.LabelsPosition = 0

    'fam.addMenuButton(fabdesign1)
    'fam.Top = 100%y -375dip
    FloatingActionMenu1.Invalidate
   
    FloatingActionMenu1.showMenuButton(True)
End Sub


Sub fam_onMenuToggle(opened As Boolean)
    Log($"fam_onMenuToggle(${opened})"$)
End Sub

Sub fam_onClick(obj As Object)
    'Dim menu As FloatingActionMenu = Sender
   
    Dim btn As FloatingActionButton = obj
    Log($"fam_onClick(${btn})"$)
    fam.toggle(True)
End Sub


Sub fab_onClick(obj As Object)
    If obj Is FloatingActionButton Then
        Dim btn As FloatingActionButton = obj
        Log($"fab_onClick(${btn.LabelText})"$)
    End If
    If obj Is Label Then
        Dim lbl As Label = obj
        Log($"fab_onClick(Label: ${lbl.Text})"$)
    End If
End Sub

Sub creazione_action_bar_e_menu
    Dim xml As XmlLayoutBuilder
   
    NavDrawer.InitDrawerToggle
   
    'Initialize the Menu-Listener for the Toolbar so we can react on the HomeButton press.
    ToolBar.InitMenuListener
   
    'ToolBar.Title="Status information"
    'ToolBar.SubTitle = ""
   
   
    '----------------------------------------------------
    'menu principale che si apre a sinistra
    'inizio
    '----------------------------------------------------
    NavDrawer.NavigationView.LoadLayout( "navheaderLayout.bal", NavDrawer.DefaultHeaderHeight)
   
    NavDrawer.NavigationView.Menu.AddWithGroup2(2, 10, 1100, "Home",  xml.GetDrawable("ic_home_black_24dp"))
    NavDrawer.NavigationView.Menu.AddWithGroup2(2, 20, 1200, "I mie dati", xml.GetDrawable("ic_help_black_24dp"))
    NavDrawer.NavigationView.Menu.AddWithGroup2(2, 30, 1300, "Esci", xml.GetDrawable("ic_exit_black_24dp"))
    NavDrawer.NavigationView.Menu.SetGroupCheckable(2, True, True)

    PC.Initialize


    '-----------------------------------------------------------------
    'creazione tab
    '-----------------------------------------------------------------


    Dim i As Int
   
    '-----------------------
    'Istantanea
    '-----------------------
       
    i=0
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    p.LoadLayout("frmMenu")
    Dim pageName As String = "Menu"
    PC.AddPage(p, pageName)
   
   
   
    'ridimensiona_menu
    i=1
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    p.LoadLayout("frmSocialWall")
    Dim pageName As String = "Social"
    PC.AddPage(p, pageName)
   
    'ridimensiona_social_wall


    '--------
   
    i=2
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    p.LoadLayout("frmRecensioni")
       
    Dim pageName As String = "Recensioni"
    PC.AddPage(p, pageName)
   
    'ridimensiona_recensioni
   
    'Set the PageContainer for the ViewPager
    VP.PageContainer = PC
   
    'Set color for the tab indicator.
    Dim Ac As AppCompat
    TabLayout.Color = Ac.GetThemeAttribute("colorPrimary")
   
    'Connect the TabLayout with the Viewpager. This will keep tabs and pages
    'in sync and creates a nice indicator animation.
    TabLayout.SetViewPager(VP)

    TabLayout.SelectTab(1)

End Sub


   
   
Sub visualizza_info_menu
    Dim photourl As String = fp.leggi_parametro("photo","")
    Dim nominativo As String = fp.leggi_parametro("nome_cognome","")
    Dim email As String = fp.leggi_parametro("email","")
   
    If photourl<>"" Then
       
        Dim links As Map
        links.Initialize
        links.Put(ImageViewPhotoProfile, photourl)
        CallSubDelayed2(ImageDownloader, "Download", links)
        ImageViewPhotoProfile.Visible=True
    Else
        ImageViewPhotoProfile.Visible=False
       
    End If
   
    If nominativo<>"" Then
        Label2.Text="di " & nominativo
    End If
   
    If email <> "" Then
        Label3.Text=email
    End If
End Sub



Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


'Event sub that handles the case if a navigation item is selected.
Sub NavDrawer_NavigationItemSelected (MenuItem As ACMenuItem, DrawerGravity As Int)
   
    Select Case MenuItem.GroupId
        Case 2
            Select Case MenuItem.Id
                Case 10
                    ToastMessageShow("Sei già in Home", True)
                    'StartActivity(frmTicket)
                    'Activity.Finish
                Case 20
                    'StartActivity(frmControlBoard)
                    Activity.Finish
                Case 30
                    gestione_uscita
           
            End Select
           
    End Select
    NavDrawer.CloseDrawers
End Sub


private Sub gestione_uscita
    Dim messaggio As String = ""
    messaggio = messaggio  & "Vuoi uscire da JOX?" & CRLF
   
    Dim KillApp As Int
    KillApp = Msgbox2(messaggio ,"Richiesta Conferma", "Si", "", "No", Null)
   
    If KillApp = DialogResponse.POSITIVE Then
       
   
        ExitApplication
    Else
        Return
    End If
End Sub

#Region ToolBar Events
'Open or Close the drawer if the Toolbar HomeButton is clicked.
Sub Toolbar_NavigationItemClick
    If NavDrawer.IsDrawerOpen Then
        NavDrawer.CloseDrawer
    Else
        NavDrawer.OpenDrawer
    End If
End Sub

Sub TabLayout_TabSelected(Index As Int, SelectedTab As String, Tag As Object)
    ricarica_tab(Index)
End Sub

Sub ricarica_tab(Index As Int)
   
   
End Sub
 
Last edited:

uniplan

Active Member
Licensed User
Longtime User
i solved the error and i try to load Layout with floating action menu inside tab...
when i create the tab call this instruction...but the floating button not appear on tab...

B4X:
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.White
    p= carica_menu_float(p)
    Dim pageName As String = "Social"
    PC.AddPage(p, pageName)

B4X:
Sub carica_menu_float(p As Panel) As Panel
    p.LoadLayout("frmSocialWall")
    FABs.Initialize
    FloatingActionMenu1.ActivityHeight = 100%y
    FloatingActionMenu1.ActivityWidth = 100%x



    FloatingActionMenu1.Animated = True
    'fam.hideMenuButton(False)
    FloatingActionMenu1.IconAnimated = True
    'fam.ClosedOnTouchOutside = True
    'fam.AnimationDelayPerItem = 25
    'fam.MenuButtonLabelText = "Hallo B4A-World!"
    'fam.MenuButtonColorNormal = Colors.Yellow
    'fam.MenuButtonColorPressed = Colors.Blue
    'fam.Invalidate

    '
    ' I don´t know what the problem is, but the
    ' first 2 Fabs added will be ignored
    ' (they do not show in menu)
    '
    ' 1
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_accessibility"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Green
    btn1.ColorPressed = Colors.Magenta
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 1
    btn1.ShowShadow = True
    btn1.showButtonInMenu(True)
    btn1.LabelText = "Mööp 1"
    FloatingActionMenu1.addMenuButton(btn1)

    ' 2
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_accessibility"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Green
    btn1.ColorPressed = Colors.Magenta
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = True
    btn1.showButtonInMenu(True)
    btn1.LabelText = "Mööp 2"
    FloatingActionMenu1.addMenuButton(btn1)

    '
    ' From here the fab is added to the menu
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_accessibility"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Green
    btn1.ColorPressed = Colors.Magenta
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    'btn1.LabelVisibility = 1
    btn1.LabelText = "Hello B4A-World!"
    ' 3 (First)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_circle_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Magenta
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 0
    btn1.LabelText = "DonManfred is proud to present a new Menu"
    ' 4 (Second)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)


    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_box_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.LightGray
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 1
    btn1.LabelText = "a new Type of Menu"
    ' 5 (Third)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_balance_wallet_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Blue
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 1
    btn1.LabelText = "FloatingActionMenu"
    ' 6 (4th)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    
    Dim btn1 As FloatingActionButton
    btn1.Initialize("fab")
    btn1.IconDrawable = "ic_account_balance_black_24dp"
    btn1.Color = Colors.Blue
    btn1.ColorDisabled = Colors.LightGray
    btn1.ColorNormal = Colors.Red
    btn1.ColorPressed = Colors.Red
    btn1.ColorRipple = Colors.White
    btn1.ButtonSize = 0
    btn1.ShowShadow = False
    btn1.showButtonInMenu(True)
    btn1.LabelVisibility = 1
    btn1.LabelText = "*grins*"
    
    ' 5 (Third)
    FloatingActionMenu1.addMenuButton(btn1)
    FABs.Add(btn1)

    FloatingActionMenu1.OpenDirection = 0
    FloatingActionMenu1.LabelsPosition = 0

    'fam.addMenuButton(fabdesign1)
    'fam.Top = 100%y -375dip
    FloatingActionMenu1.Invalidate
    
    FloatingActionMenu1.showMenuButton(True)
    Return p
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

uniplan

Active Member
Licensed User
Longtime User
I added #AdditionalRes: ..\resource into MAIN...
if I add this code into my Activity, i have this message error: "Attribute Not supported"
 
Upvote 0

uniplan

Active Member
Licensed User
Longtime User
ok....it's already added, but i have the same problem...i don't see nothig.
it's correct what i do?
 
Upvote 0
Top