How to Add Option / settings menu to android App


Add this to your mainactivity:

public boolean onCreateOptionsMenu(Menu menu){
    // Create menu
    // See onOptionItemSelected for actions when clicked

    Menu settingsMenu = menu;
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);

    MenuItem settingsMenuLogin = settingsMenu.findItem(;

return true;


public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == {
        // add additional check
        Intent i = new Intent(getApplicationContext(), export.class);
    return super.onOptionsItemSelected(item);

and create an xml in res\menu like this:


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android=""
        app:showAsAction="never" />


5735 Total Views 2 Views Today

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments Protected by WP-SpamShield Spam Blocker