Understanding why onCreateOptionsMenu is not displaying a menu

后端 未结 4 488
故里飘歌
故里飘歌 2021-01-21 12:11

I\'m reading through Android For Dummies. One example makes use of the onCreateOptionsMenu (I\'ve added a log message):

@Override
public boolean onCreateOptionsM         


        
相关标签:
4条回答
  • 2021-01-21 12:43

    Call the super method after inflating it

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater mi = getMenuInflater();
        mi.inflate(R.menu.list_menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
    0 讨论(0)
  • 2021-01-21 12:45

    onCreateOptionsMenu() is called when activity created .We dont need to call it explicitly. Check whether your activity has title bar or not.If dont then make it visible or remove no title bar property in activity.Try it may it work.

    0 讨论(0)
  • 2021-01-21 12:55

    This question is answered here:

    My menu in my activity is not appearing because my onCreateOptionsMenu is not getting called

    I had the same problem whilst studying this book. The code is right, but you have to press the menu button in order for it to appear. :)

    0 讨论(0)
  • 2021-01-21 12:59

    I would remove the line super.onCreateOptionsMenu(menu); and try it again. This is also exemplified in Androids Inflating a Menu Resource section.

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