Menu and options menu together

398 views Asked by At

how can I create a mainmenu in the actionbar and also an "options" menu that will open on hardware button click?

Like Whatsapp. There's an actionbar with avatar, name and and icon and if you press "menu" button, it will appear another menĂ¹ with "Show contact, media, search" etc.

This is my actual code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.calendar, menu);
    return true;
}

@Override
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 == R.id.action_legend) {
        // Open dialog
    } else if(id == R.id.action_settings) {
        startActivity(new Intent(this, SettingsActivity.class));
    } else if(id == R.id.action_add) {
        startActivity(new Intent(this, AddActivity.class));
    }
    return super.onOptionsItemSelected(item);
}

@Override
public boolean onKeyDown(int keycode, KeyEvent e) {
    switch(keycode) {
        case KeyEvent.KEYCODE_MENU:
            // Here open the options menu
            return true;
    }

    return super.onKeyDown(keycode, e);
}
0

There are 0 answers