DFdou's Blog Life is short,Be yourself.

502/108

Android-How to create an option menu

This post learned from http://www.droidnova.com/how-to-create-an-option-menu,427.html,
droidnova.com is very good site about Android dev,.

Today we learn how you can create an option menu for your application.
Lets start with an empty android project. The package name will be com.droidnova.android.howto.optionmenu and the activity will have the name SimpleOptionMenu.

Our activity should now look very familiar to us:

package com.droidnova.android.howto.optionmenu;

import android.app.Activity;
import android.os.Bundle;

public class SimpleOptionMenu extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

First we have to make a new folder in our res/ directory named menu. In this new directory we will create a new xml file named menu.xml.

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/icon"
        android:icon="@drawable/icon" />
    <item android:id="@+id/text"
        android:title="Text" />
    <item android:id="@+id/icontext"
        android:title="Icon and text"
        android:icon="@drawable/icon" />
</menu>