Tag Archives: tutorials

Creating a menu

A menu is the component that pops up when you press the menu button. The design of the menu is held as an xml and then implemented in java. So to do it, I created a separate folder known as menu that will contain the menu files ie nice_menu.xml. Eclipse automatically detects that you are creating a menu and when you create a new xml it will open a file that looks something like this:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="" >


<item /> adds a label like the preferences or exit. The id is so that you can reference in java and add methods to detect when that particular option has been selected. There are more stuff here, Its a great read like you could add icons, I’ll do that in the next blog post along with the method that detects which item has been selected. For now the menu does nothing when clicked.

Going to the java side of this. We need to inflate the menu (show the menu on screen). You have to implement the onCreateOptionsMenu(Menu).

public boolean onCreateOptionsMenu(Menu menu){
		MenuInflater showMenu = getMenuInflater();
		showMenu.inflate(, menu);

		return true;

To view the complete source code for the camera app with menu included: Click here


Posted by on July 1, 2012 in Android, Code


Tags: ,