Android action bar not showing overflow menu

My Android app supports 2.2 or more. I use the appcompat support library for the action bar, so it should only show if there are things that don't fit. I want my action bar to support an overflow button (three vertical squares) that shows a menu with other elements when clicked.

In my menu file, I have three elements. However, in the application, I see only two of them, and the overflow button also does not appear.

activity_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:sord.ids_connect="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_settings" android:icon="@drawable/checkbox" android:title="@string/action_settings" sord.ids_connect:showAsAction="ifRoom" /> <item android:id="@+id/action_settings2" android:icon="@drawable/checkbox_checked" android:title="@string/action_settings" sord.ids_connect:showAsAction="ifRoom" /> <item android:id="@+id/action_settings3" android:icon="@drawable/ic_launcher" android:title="@string/action_settings" sord.ids_connect:showAsAction="ifRoom" /> </menu> 

java file

 import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBarActivity; public class Activity_Menu extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_menu); ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_menu, menu); //return true; return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: super.onBackPressed(); return true; } return super.onOptionsItemSelected(item); } } 

manifest

  <activity android:theme="@style/Theme.AppCompat.Light.DarkActionBar" android:name="sord.ids_connect.Activity_Menu" android:screenOrientation="portrait" android:label="@string/title_activity_menu" > </activity> 
+6
source share
7 answers

General recommendation

1 - Override onCreateOption and inflate the menu

Note

It doesn't matter if you return true or call super

 @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_menu, menu); return super.onCreateOptionsMenu(menu); } 

2 - add the namespace to the menu.xml file.

 xmlns:**yourapp**="http://schemas.android.com/apk/res-auto" 

3 - set showAsAction to always or ifRoom

 **yourapp**:showAsAction="ifRoom" 

4 - if you use appcompat, make sure that your activity extends ActionBarActivity , you do not need to change any ActionBar value to be able to see your Option menu in the panel.

Finally, you will have something like [remember the user the correct namespace for yourapp ]

main.xml

 <item android:id="@+id/action_settings" android:icon="@drawable/ic_action_settings" android:title="@string/action_settings" yourapp:showAsAction="ifRoom" /> 

in your activity

 @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return super.onCreateOptionsMenu(menu); } 
+14
source

If you use the support library, you need to declare showAsAction from your own namespace; which will look like this app:showAsAction . You can contact eOnOe for an answer.

Using android:showAsAction will not work with the support library as it uses its own implementation of the action bar, not its implementation.

You can also always group items into an icon, for example:

 <item ... android:icon="@drawable/abs__ic_menu_moreoverflow_holo_dark"> <menu> <item .../> <item .../> </menu> </item> 
+7
source

The Android Overflow Display menu is only displayed if your device does not have a menu button. Of course, you can create a default hack for all devices, but this is not recommended. And for your elements, add android:showAsAction="never" , and that says your device shows an overflow menu if you don't have a menu button.

+2
source

Im testing on my phone, and when I press the menu button, I see that the menu is displayed at the bottom, with only 1 option that says β€œSettings”

This is an overflow.

also why only 1 parameter appears there when I have 3 elements in a menu file?

Because the other two are in the action bar. You specified ifRoom , and there was room for two, not three.

+1
source

You need to select the menu as shown below

 <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:sord.ids_connect="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_container" android:title="Menu" android:showAsAction="never"> <item android:id="@+id/action_settings" android:icon="@drawable/checkbox" android:title="@string/action_settings" sord.ids_connect:showAsAction="ifRoom" /> <item android:id="@+id/action_settings2" android:icon="@drawable/checkbox_checked" android:title="@string/action_settings" sord.ids_connect:showAsAction="ifRoom" /> <item android:id="@+id/action_settings3" android:icon="@drawable/ic_launcher" android:title="@string/action_settings" sord.ids_connect:showAsAction="ifRoom" /> </item> </menu> 
0
source
  Change Your menu.xml with the following code. <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:sord.ids_connect="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_container" android:title="Menu" android:showAsAction="always"> <item android:id="@+id/action_settings" android:icon="@drawable/checkbox" android:title="@string/action_settings" android:showAsAction="always"/> <item android:id="@+id/action_settings2" android:icon="@drawable/checkbox_checked" android:title="@string/action_settings" android:showAsAction="always" /> <item android:id="@+id/action_settings3" android:icon="@drawable/ic_launcher" android:title="@string/action_settings" android:showAsAction="always" /> </item> </menu> 
0
source

I had the same problem. I solved this:

1) commenting out return true;

2) uncomment return super.onKeyUp(keyCode, event);

in the public boolean onKeyUp(int keyCode, KeyEvent event)

-2
source

All Articles