Opening submenu in action bar on Hardware menu button click

后端 未结 1 631
孤独总比滥情好
孤独总比滥情好 2020-12-29 06:48

Title explains everything. I want to open a submenu in actionbar when clicking Hardware menu button

This is the code and it works fine first time i click menu. Every

相关标签:
1条回答
  • 2020-12-29 07:08

    Try this:

    public boolean onCreateOptionsMenu(Menu menu) 
    {
        super.onCreateOptionsMenu(menu);// <--- add this
    
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.options, menu);
        mainMenu = menu;
        return true;
    }
    
    //override this method instead of onKeyDown()....
    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        super.onOptionsItemSelected(item);      
    
        int menuId = item.getItemId();      
        if(menuId == R.id.settings)
        {
            //do settings   
        }
        //else if(menuId = ...) {....}
    
        return true;
    }
    
    0 讨论(0)
提交回复
热议问题