Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onCreateOptionsMenu is never called

I am having some trouble getting an options menu working in Android. I have built apps before, and they all worked fine, but now the menu just doesn't pop up.

The code:

@Override public boolean onCreateOptionsMenu(Menu menu) {     super.onCreateOptionsMenu(menu);      getMenuInflater().inflate(R.menu.activity_video, menu);     return true; } 

the whole method is never even called (checked by setting a breakpoint). The activity is super-simple, it just has a VideoView in it, with an OnTouchListener set.

I am using Android 4.0.4 on a Samsung Galaxy 10.1, API level 15, minSDK 15. Am I missing something?

like image 957
Bart Friederichs Avatar asked Nov 07 '12 09:11

Bart Friederichs


1 Answers

In the latest versions of Android when using the compat library for toolbar, is very common that this happens, in order to get the menu items to display in the toolbar you must do the following:

mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); 
like image 190
Martin Cazares Avatar answered Sep 18 '22 02:09

Martin Cazares