Search code examples
androidoncreateoptionsmenu

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?


Solution

  • 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.