In Appcelerator Titanium, setting up a menu is very easy. The menu system works with Titanium.UI and the Menu object.
To create a new menu object, all you have to do is:
var menu = Titanium.UI.createMenu();
Now, a menu without any menu items is a rather useless feature, so now we need to add some menu items.
var file = menu.addSubMenu("File");
var help = menu.addSubMenu("Help");
file.addItem("Open", function () { alert('Do open');});
file.addSeparator();
file.addItem("Exit", function () { Titanium.App.exit(); });
help.addItem("About", function () { alert('Show about box here'); });
The menu.addSubMenu(textToDisplay) function adds a submenu to the menu, and returns the submenu object. Menu items are then added to the submenu with the .addItem(textToDisplay, functionToExecute). You can, of course, add submenus to a submenu in the same way as a submenu is added to the main menu.
The last step is to tell Titanium that you want to display the menu, and that is done with this command:
Titanium.UI.setMenu(menu);
That is all there is to it. Nothing hard about it at all. For the full list of methods for the Menu object see the Titanium API Documentation.
Related posts:
- Titanium Tutorial: Using the file selection dialog boxes Appcelerator Titanium enables you to show a dialog box to...
- Titanium Tutorial: Browsing folder contents programmatically A very useful feature of desktop applications is being able...
- Titanium Tutorial: Window management Appcelerator Titanium has a rich set of Window management methods...
- Titanium Tutorial: Calling the Titanium API from a remote file Appcelerator Titanium is pretty free with what it allows you...
- Titanium Tutorial: Accessing files on the local system Out of all the features included in Appcelerator Titanium which...
Related posts brought to you by Yet Another Related Posts Plugin.
Serge Meunier is a software developer living in Cape Town, South Africa. He loves programming, fencing, philosophy, feeding his internet addiction, and, of course, dogs.
Comments