An Android style menu class

Discussion in 'iOS Code Snippets' started by Didier9, Jul 19, 2018.

  1. Didier9

    Didier9 Active Member Licensed User

    I should say that starting on B4i after a couple of years learning B4A was not easy.
    Even though Erel has done a great job smoothing out the differences, Android and iOS simply want to do things differently.
    Not wanting to pass judgement on which is best, my goal was simply to reproduce a similar environment for me to be able to migrate apps from Android to iOS and to give them a similar feel.
    A couple of features that I like to use in B4A and which are missing (or implemented too differently to my taste) are the menus and the Toast messages.
    So I created a new class to emulate the Android menus.
    I also found a ToastMessage class for B4i written by Pendrush (thanks a lot!), which I tweaked to make it really look more like the one on Android.
    The project below shows the two classes in action.

    Example:
    1. Declare the class in Process_Globals:
    Code:
    Private Menu As clsMenu
    2. Initialize the class and load the menu options in Application_Start:
    Code:
    Menu.Initialize( PageMain, 17 )
        
    Menu.AddMenuItem( "Sub1""mnuSub1" )
        
    Menu.AddMenuItem( "Sub2""mnuSub2" )
        
    Menu.AddMenuItem( "About""mnuAbout" )
    3. Open the menu by clicking on the Navigation bar element (set in the designer)
    Code:
    Sub PageMain_BarButtonClick( Tag As String)
        
    If Tag = "Menu" Then
            
    If Menu.Visible = False Then
                
    Menu.Show
            
    Else
                
    Menu.hide
            
    End If
        
    End If
    End Sub ' Page_BarButtonClick
    Note: The Menu class is usable with very few modifications on Android. You may ask why. It turns out I have a couple of older Android devices intended for home automation (Wink Relay) running a crippled version of Android 4.4 which does not support the menus (they do not have the navigation bar either), so I imported the clsMenu class, replaced the TableView with a ListView and adapted the code to the few associated differences and voila. I will post the Android clsMenu class later if there is interest.
     

    Attached Files:

    Last edited: Jul 19, 2018
    Alexander Stolte likes this.
  2. Alexander Stolte

    Alexander Stolte Well-Known Member Licensed User

    On Android, the ToastMessage are maybe 10dip on the bottom, but this ToastMessage are 60%y (felt), is this normal? (6S Plus)
     
  3. Didier9

    Didier9 Active Member Licensed User

    I set it there because I tend to have other status info displayed at the bottom of the screen on my apps and I did not want to cover than.
    This can easily be changed in the clsMenu module.
     
    Alexander Stolte likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice