Skip to content
Advertisement

Why click on optionsMenu item doesn’t work?

I have a problem when clicking on an item from an options menu. I’ve read how to create a menu on the website https://developer.android.com/guide/topics/ui/menus and I seem to do it right, but it still doesn’t work. The menu exists, it is visible, but nothing happens when I perform the click. Also, there are no errors in the Logcat.

The XML file for the menu is:

JavaScript

EDIT: Neither of the Toasts messages are displayed and the menu closes after performing click on an item.

The menu has one item on the toolbar, and the others in the dropdown menu: menu_on_toolbar dropdown_menu

As requested, here is the XML code for my activity:

JavaScript

and the java class:

JavaScript

I don’t use the ActionBar, but another Toolbar I created, and I had set for the entire app a style with NoActionBar. <style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">

Thanks in advance!

Advertisement

Answer

Try add this line in your initialization method:

setSupportActionBar()

Well, you need to set support action bar setSupportActionBar(); and pass your toolbar variable, like this:

setSupportActionBar(toolbar);

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement