public final class

Menu

extends Object
java.lang.Object
   ↳ com.neomades.ui.menu.Menu

Class Overview

The Menu of the native platform.

This class doesn't need to be instantiated. Each menu belongs to a Screen, which you can retrieve by overriding the Screen.onMenuCreate(Menu) method.

Add a menu to a Screen

The following code explains how to add a menu in a screen by overriding onMenuCreate(Menu):

 public MyScreen extends Screen {
 
 	protected void onMenuCreate(Menu menu) {
 		menu.addItem(new MenuItem("Item 1"));
 	}
 
 }
 

Menu in composed screens (SplitScreen, SlideScreen, TabScreen...)

Menu can be added in complex screens like TabScreen, SplitScreen or SlideScreen and in their child screens inside. The menu in composed screens (parent screen) will be shared between all the child screens which composed the parent screen. If a child screen has its own menu, it will be combined with the parent screen menu. The first items in the menu will be the menu items in the parent screen.

MenuItem in the action bar (title bar)

MenuItem can be added in the action bar using setAsLeftAction() and setAsRightAction(). Items will be placed to the left or to the right of the title in the bar. Only one item can be set to the left of the title. If there are several items set as left, only the first will be set to the left, the others will be set to the right. The left action bar button item is by default the back button. If it is replaced by an other menu entry, be sure to implement an other way to exit the screen.

Cross Platform Considerations

Android

Contextual menu or action bar

In Android, the default menu is an Options Menu associated with the menu button. It is opened by clicking on the menu button. By default, MenuItem will be added in this menu.

If the action bar is activated in the application (done by using setActionBarEnabled(boolean) in the application main class), MenuItem can be added in the action bar. Use setAsLeftAction() and setAsRightAction() to place items to the right or to the left of the title in the action bar.

iOS

Tool bar or action bar

In iOS platform, the default menu is shown as an UIToolbar. This tool bar will occupy around 40dp at the bottom of the screen and will be displayed only if the menu contains simple menu items.

Otherwise, MenuItem can be added in the action bar using setAsLeftAction() and setAsRightAction(). Items will be placed to the left or to the right of the title in the bar.

Note: To provide the right image sizes for each platform, see MenuItem documentation.

See Also

Summary

Constants
int STYLE_BLACK iOS UIToolBar Style Black
int STYLE_DEFAULT iOS UIToolBar Style Default
Public Methods
void addItem(MenuItem item)
Adds an item to the menu.
void addSeparator()
Adds a separator in the menu.
void addSubMenu(SubMenu menu)
Adds an item with a sub-menu.
void clear()
Remove all the items from the menu
boolean isEmpty()
Checks if the menu is empty, there are no items in it.
boolean isVisible()
Checks whether the menu is visible.
void setStyle(int style)
Sets the iOS Menu UIToolBar style (bar at the bottom of the screen).
void setTranslucent(boolean translucent)
Sets the iOS Menu UIToolBar translucent or not (bar at the bottom of the screen).
void setVisible(boolean visible)
Shows or hides the menu.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int STYLE_BLACK

iOS UIToolBar Style Black

Constant Value: 0 (0x00000000)

public static final int STYLE_DEFAULT

iOS UIToolBar Style Default

Constant Value: 0 (0x00000000)

Public Methods

public void addItem (MenuItem item)

Adds an item to the menu.

Parameters
item the item to add

public void addSeparator ()

Adds a separator in the menu.

Cross Platform considerations

For iOS: it adds a space between two items in the menu in the tool bar at the bottom of the screen. Note that separators are always added in the tool bar. They cannot be added between MenuItem in the action bar.

For Android, this method does nothing.

public void addSubMenu (SubMenu menu)

Adds an item with a sub-menu. A SubMenu is a MenuItem with a specific action: it always opens an other menu (sub menu) with a list of menu items. It can help to create more complex menu structure.

Parameters
menu the sub menu item to add
See Also

public void clear ()

Remove all the items from the menu

public boolean isEmpty ()

Checks if the menu is empty, there are no items in it.

Returns
  • true if the menu is empty, false otherwise

public boolean isVisible ()

Checks whether the menu is visible.

Returns
  • true if visible

public void setStyle (int style)

Sets the iOS Menu UIToolBar style (bar at the bottom of the screen). STYLE_DEFAULT for the classical blue theme, STYLE_BLACK for the iOS black theme.

Cross Platform considerations

In Android, this method has no effect.

Parameters
style the iOS Style

public void setTranslucent (boolean translucent)

Sets the iOS Menu UIToolBar translucent or not (bar at the bottom of the screen).

Cross Platform considerations

In Android, this method has no effect.

Parameters
translucent true if the bar must be translucent

public void setVisible (boolean visible)

Shows or hides the menu.

Cross Platform considerations

In iOS, this method has no effect.

Parameters
visible true to set the menu visible.