Himanshu
Himanshu

Reputation: 1086

How to create custom option menu in android

I am creating an option menu. it has three option HOME, EMAIL, VISIT. All three options coming at the same row. i have to show HOME option above and rest two below to Home Option(according to attached Screen Shot).

Any Ideas?? Thanks.

enter image description here

Here is my XML file.

<menu android:id="@+id/new_game"
          android:icon="@drawable/red_no_bg"
          android:title="Home" />
    <item android:id="@+id/email"
          android:icon="@drawable/red_no_bg"
          android:title="Email" />
    <item android:id="@+id/help"
          android:icon="@drawable/red_no_bg"
          android:title="Visit Microsite" />
</menu>

Here is my code.

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.overview_menu, menu);
        return true;
    }

Using the above code i am getting the all option in Same line.

Upvotes: 3

Views: 29875

Answers (1)

Gowtham Kumar
Gowtham Kumar

Reputation: 544

You can Create in two ways

1.Statically.

2.Dynamically.

Am explaining the easiest method of adding menus.

Step 1: Create a new Android Application.

Step 2: After onCreate() method write onCreateOptionMenu();

Step 3: In onCreateOptionMenu() Write these lines

menu.add(11, 21, 1, "Gowtham").setIcon(R.drawable.ic_launcher);

Here "Gowtham" is title of your menu item You can Home&Email use instead of "Gowtham".

Ans use Any images Instead of ic.launcher

Upvotes: 2

Related Questions