Home » Android » java – Items not showing in the ActionBar with showAsAction=“always”

java – Items not showing in the ActionBar with showAsAction=“always”

Posted by: admin May 14, 2020 Leave a comment


I’m new to Android programming and currently trying to get the Actionbar working. My problem is, that although I set an item in the XML file to “always”, it constantly ends up in the overflow menu no matter what I try. I found several similar problems on here, but none of the solutions fixed the problem.

Additional info: The ic_action_search icons are in the drawable folders of the project.


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"

<!-- Search, always displayed -->
<item android:id="@+id/action_search"
      app:showAsAction="always" />

<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
      app:showAsAction="never" />


<?xml version="1.0" encoding="utf-8"?>

  <string name="app_name">My First App</string>
  <string name="edit_message">Enter a message</string>
  <string name="button_send">Send</string>
  <string name="action_settings">Settings</string>
  <string name="action_search">Search</string>
  <string name="title_activity_main">MainActivity</string>
  <string name="title_activity_display_message">My Message</string>
  <string name="hello_world">Hello world!</string>

In MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);

Thanks for your help!

How to&Answers:

try android:showAsAction instead of app:showAsAction. Or if you’re using the appcompat_v7 backport, use both android:showAsAction and app:showAsAction(Thanks to Commonsware).