OnCreateOptionsMenu() not called in Fragment

If you are using a theme that does not support ActionBar, then OnCreateOptionsMenu() will not be called automatically, even you wrote all Java codes properly.

You can open AndroidManifest.xml, change the value of android:theme to "@android:style/Theme.Holo.Light.DarkActionBar", or any other themes that support ActionBar.


In your fragment's onCreateView() method, you need to call setHasOptionsMenu(true) to tell the host activity that your fragment has menu options that it wants to add.