How to get add menu in a group or add separator in RocketWeb Android?

Successfully configure connect the app with .io but don’t find any option to add menu in a group or add a separator between them.

For example, I add 3 menus here and want to separate in 2 categories

  • Website
  • Share

So, first of all, I add my all menu on the configuration page. Now want to add InfixSoft and Help under the menu group Website. And Share App under Share group. Like the menu here:

After setting the .io file now go to the HomeActiviry.kt page and change this method.

Here is the code carefully replies the method initSliderMenu(). Remember that the method start and end with brackets ‘{‘ & ”}’

private fun initSliderMenu() {
val navigationMenu = navigation_view.menu
navigationMenu.clear()

/**
* If you need to add menu with icon
* menu.add(0, R.string.menu_home, Menu.NONE, R.string.menu_home).setIcon(R.drawable.ic_home)**/

var subMenu: SubMenu
subMenu = navigationMenu.addSubMenu("Home")
subMenu.add(0, R.string.menu_home, Menu.NONE, getString(R.string.menu_home)).setIcon(R.drawable.ic_home)

var i = 1
for(menu in AppDataInstance.navigationMenus){
when(menu.url) {
"ABOUT" -> subMenu.add(i++, R.string.menu_about, Menu.NONE, getString(R.string.menu_about)).setIcon(R.drawable.ic_info)
"RATE" -> subMenu.add(i++, R.string.menu_rate, Menu.NONE, getString(R.string.menu_rate)).setIcon(R.drawable.ic_rate)
"SHARE" -> subMenu.add(i++, R.string.menu_share, Menu.NONE, getString(R.string.menu_share)).setIcon(R.drawable.ic_share)

"http://infixsoft.com/" -> {
subMenu = navigationMenu.addSubMenu("Website")
subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.ic_label)
}

"http://help.infixsoft.com//" -> {
//subMenu = navigationMenu.addSubMenu("")
subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.ic_label)
}

"https://play.google.com/store/apps/details?id=infix.imrankst1221.rocket.web" -> {
subMenu = navigationMenu.addSubMenu("Share app")
subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.ic_label)
}

// In cage you need to user custom icon
// "http://infixsoft.com/" -> subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.ic_label)
else -> subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.ic_label)
}
}

}

Explain:

  1. Because I want to add 1st menu is “Home” so add it on top.
  2. Because I want to add “Website” before URL “http://infixsoft.com/” so set a group before it “navigationMenu.addSubMenu(“Website”)“.
  3. Because “Help” already set after the “InfixSoft” it’s auto-add under “Website” group.
  4. And finally “Share app” group add before URL “https://play.google.com/store/apps/details?id=infix.imrankst1221.rocket.web

Tips:

The main game change is this line so as per your requirement add menu logic for you.

"http://infixsoft.com/" -> {
subMenu = navigationMenu.addSubMenu("Website")
subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.ic_label)
}

If you want to change the icon of the menu then set your icon (must be on .png formate) on the drawable folder and set the name here

subMenu.add(i++, i-2, Menu.NONE, menu.menu).setIcon(R.drawable.[your image])

By default it’s will open inside app but if you want to open URL ourside of app then:

Not only from the menu from anywhere is the URL you want to open outside of app add this line. For multiple add multiple. In below example google and infix website will open optside of app. Make sure that you put full url. If you got error then make sure that your RocketWeb version need to be 1.3 or above.

if(url == "http://infixsoft.com/"){
    UtilMethods.browseUrlExternal(mContext, url)
    return true
}
image.png

What if you want to open all the URL under any domain then it’s not possible to write multiple conditions. So for that solution is:

if(url.contains("http://infixsoft.com/")){
    UtilMethods.browseUrlExternal(mContext, url)
    return true
}

4 thoughts on “How to get add menu in a group or add separator in RocketWeb Android?

  1. SebbyPHM says:

    I have a problem. If i click on the right button of the header, after this the group-names in the “sub”menu are aligned right and not left. How can i fix it?
    In your example, after click on “Reload”, the items/titles “home, website, share” are aligned right.

Leave a Reply