Menu items rendered in ActionBar work, and those that can be seen only when the menu is opened do not respond to a click. If you change the values ​​in the showAsAction and orderInCategory attributes to bring out the item3 and settings elements in the ActionBar, they will work fine, and the other two will not.

@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); return super.onCreateOptionsMenu(menu); } //Обработчик для меню @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.item1: Toast.makeText(this, "111", Toast.LENGTH_SHORT).show(); return true; case R.id.item2: Toast.makeText(this, "222", Toast.LENGTH_SHORT).show(); return true; case R.id.item3: Toast.makeText(this, "333", Toast.LENGTH_SHORT).show(); return true; case R.id.settings: Toast.makeText(this, "444", Toast.LENGTH_SHORT).show(); return true; } return super.onOptionsItemSelected(item); } 

The xml code is:

 <?xml version="1.0" encoding="utf-8"?> <menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/settings" android:orderInCategory="100" android:title="@string/menu_settings" app:showAsAction="never"/> <item android:id="@+id/item1" android:orderInCategory="1" android:title="@string/menu_item1" android:icon="@drawable/icon_emojiconfused_white" app:showAsAction="ifRoom"/> <item android:id="@+id/item2" android:orderInCategory="2" android:title="@string/menu_item2" android:icon="@drawable/icon_osclass" app:showAsAction="ifRoom"/> <item android:id="@+id/item3" android:orderInCategory="3" android:title="@string/menu_item3" app:showAsAction="never"/> </menu> 
  • I have the same problem ... only with Rich Box dialogue alert - Sanaev
  • all you have written correctly. most likely android studio tupit - Sanaev
  • try rebuilding the project. - Sanaev
  • Show how it attaches to ActionBar - Barmaley
  • The restructuring of the project did not help. - Gleb Krishin

0