lord_sneed
lord_sneed

Reputation: 824

Android: onCreateOptionsMenu - Remove Default Menu Item

I am using the onCreateOptionsMenu and there is a default menu item that I did not program. I would like to remove it because I have no use for it and it does not do anything. Here is what it looks like:

enter image description here

I would like to get rid of the "Settings" item.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(1, 1, 0, "item1");
    menu.add(1, 2, 1, "item2");

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_name, menu);
    return true;
}

As you can see, I have not manually added it myself. How do I get rid of it?

Upvotes: 1

Views: 6007

Answers (3)

Federico Perez
Federico Perez

Reputation: 1026

The settings option is automatically generated in the menu xml by eclipse. Remove it from the xml menu and that option will be no longer shown.

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1006549

As you can see, I have not added it myself

Yes, you have. It is coming from:

getMenuInflater().inflate(R.menu.activity_name, menu);

How do I get rid of it?

Remove the aforementioned line. Or, move your Java-based Menu manipulations to res/menu/activity_name.xml and get rid of "Settings" from that file.

Upvotes: 4

Nimish Choudhary
Nimish Choudhary

Reputation: 2088

check the content of R.menu.activity_name or past the data of this xml file.

Upvotes: 0

Related Questions