Creating Options Menu for android

There is another common task in android applications is creating the options menu
Menus are an important part of an activity’s user interface, which provide users a familiar way to perform actions. Android offers a simple framework for you to add standard menus to your application.

You can find more information on menus on android development website at following url

So now we will create two simple menus one is settings and another one is about

First thing to move ahead with is to create a menu xml file which will look like as follows

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="">
    <item android:id="@+id/settings"
    <item android:id="@+id/about"


Create a new folder in the res directory and save it as menu.xml

After that create a new menu in java file as follows

 // options menu
	  public boolean onCreateOptionsMenu(Menu menu) {
	      MenuInflater inflater = getMenuInflater();
	      inflater.inflate(, menu);
	      return true;

So when click on menu button you will get the two menus created mainly settings and about

Now lets have the action that will execute upon clicking the menu

 public boolean onOptionsItemSelected(MenuItem item) {
		  switch (item.getItemId()) 
		          ShowSettingsMenu();// function to call on click on settings menu
		          ShowAboutPopup();// function to call on click on about menu

		  return false;

when you click on the menu you can start a new activity or a dialog box or any other action


Isnt it pretty simple one..


What you think ? Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s