How to open the options menu programmatically?

前端 未结 11 1577
时光说笑
时光说笑 2020-11-28 06:47

I would like to open the optionsMenu programmatically without a click on the menu key from the user. How would I do that?

相关标签:
11条回答
  • 2020-11-28 07:12
    toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        toolbar.setTitleTextColor(0xFFFFFFFF);
    
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                toolbar.showOverflowMenu();
            }
        }, 100);
    
    0 讨论(0)
  • 2020-11-28 07:13

    Put this line of code in your onResume(), this should help!

    new Handler().postDelayed(new Runnable() { 
       public void run() { 
         openOptionsMenu(); 
       } 
    }, 1000); 
    
    0 讨论(0)
  • 2020-11-28 07:17

    For developers using the new Toolbar class of the Support Library, this is how it's done:

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.showOverflowMenu();
    
    0 讨论(0)
  • 2020-11-28 07:17

    if using AppCompatActivity

    getSupportActionBar().openOptionsMenu();
    
    0 讨论(0)
  • 2020-11-28 07:19

    Or just call Activity.openOptionsMenu()?

    0 讨论(0)
提交回复
热议问题