1

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?

lord_sneed
  • 794
  • 3
  • 12
  • 25

3 Answers3

4

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I thought the getMenuInflater is what causes the list to pop up. So by removing that, wouldn't that cause the menu to not open? – lord_sneed Feb 20 '13 at 18:29
  • @lord_sneed: "I thought the getMenuInflater is what causes the list to pop up" -- no. "So by removing that, wouldn't that cause the menu to not open?" -- no. You can test this by getting rid of the line. Or, you can read the documentation for the `inflate()` method on `MenuInflater` to learn what it does: http://goo.gl/3WI23 – CommonsWare Feb 20 '13 at 18:35
  • This is the first time I have ever dealt with the onCreateOptionsMenu, so my apologies for not really paying attention to the menu folder in /res in the past. I only started teaching myself all of this no more than two months ago. – lord_sneed Feb 20 '13 at 18:44
2

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.

Federico Perez
  • 976
  • 1
  • 13
  • 34
0

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

Nimish Choudhary
  • 2,048
  • 18
  • 17