0

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);
}
Theraloss
  • 700
  • 2
  • 7
  • 30
  • look on older devices where there is hard menu key, your menu will be activate/deactivate on press of that key. No special things need to be done. – Nitin Misra Nov 09 '14 at 14:50
  • But THIS is the main menù on the actionbar and I want to show another on hardware button click. I don't think I can inflate two menus. – Theraloss Nov 10 '14 at 15:16

0 Answers0