Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android action bar not showing overflow

I have an action bar in my app with 3 items.

Only 2 can be displayed due to space issues, so I'd expect the first to be displayed and the rest to be displayed in the overflow. However in practice only the first 2 items are shown and there is no overflow detectable.

Here is the relevant code: list_menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_insert"     android:icon="@android:drawable/ic_menu_add"     android:title="@string/menu_insert"      android:showAsAction="ifRoom|withText"/> <item android:id="@+id/menu_call"     android:icon="@android:drawable/ic_menu_call"     android:title="@string/menu_call"      android:showAsAction="ifRoom|withText"/> <item android:id="@+id/menu_agenda"     android:icon="@android:drawable/ic_menu_agenda"     android:title="@string/menu_agenda"      android:showAsAction="ifRoom|withText"/> </menu> 

Activity.java

public boolean onCreateOptionsMenu(Menu menu) {     MenuInflater mi = getMenuInflater();     mi.inflate(R.menu.list_menu, menu);     return true; } 
like image 473
Mats Raemen Avatar asked Mar 16 '12 14:03

Mats Raemen


People also ask

Where is the action overflow icon on Android?

The right-hand side of the action bar shows the actions. The action buttons (3) show the most important actions of your app. Actions that do not fit in the action bar are moved to the action overflow, and an overflow icon appears on the right. Tap on the overflow icon to display the list of remaining action views.

What is ActionBar in android?

Android ActionBar is a menu bar that runs across the top of the activity screen in android. Android ActionBar can contain menu items which become visible when the user clicks the “menu” button.


2 Answers

If you want to show the three dots, irrespective of device menu button! then you can call this method in your application class' onCreate method-

private void makeActionOverflowMenuShown() {     //devices with hardware menu button (e.g. Samsung Note) don't show action overflow menu     try {         ViewConfiguration config = ViewConfiguration.get(this);         Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");         if (menuKeyField != null) {             menuKeyField.setAccessible(true);             menuKeyField.setBoolean(config, false);         }     } catch (Exception e) {         Log.d(TAG, e.getLocalizedMessage());     } } 
like image 131
Atul Kaushik Avatar answered Sep 20 '22 12:09

Atul Kaushik


Output

Action Bar

res/menu/menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" >      <!-- Search / will display always -->     <item         android:id="@+id/action_search"         android:icon="@drawable/ic_action_search"         android:showAsAction="always"         android:title="@string/action_search"/>      <!-- Location Found -->     <item         android:id="@+id/action_location_found"         android:icon="@drawable/ic_action_location_found"         android:showAsAction="always"         android:title="@string/action_location_found"/>      <!-- More -->     <item         android:id="@+id/a_More"         android:icon="@drawable/ic_action_overflow"         android:showAsAction="always"         android:title="More">         <menu>              <!-- Refresh -->             <item                 android:id="@+id/action_refresh"                 android:icon="@drawable/ic_action_refresh"                 android:showAsAction="never"                 android:title="@string/action_refresh"/>              <!-- Help -->             <item                 android:id="@+id/action_help"                 android:icon="@drawable/ic_action_help"                 android:showAsAction="never"                 android:title="@string/action_help"/>              <!-- Check updates -->             <item                 android:id="@+id/action_check_updates"                 android:icon="@drawable/ic_action_refresh"                 android:showAsAction="never"                 android:title="@string/action_check_updates"/>         </menu>     </item>  </menu> 

MainActivity.java

public class MainActivity extends Activity {      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);     }        @Override     public boolean onCreateOptionsMenu(Menu menu) {         // Inflate the menu; this adds items to the action bar if it is present.         MenuInflater inflater = getMenuInflater();         inflater.inflate(R.menu.menu, menu);           return super.onCreateOptionsMenu(menu);     }  } 

Download the Action Bar Icon Set

like image 41
Kirit Vaghela Avatar answered Sep 19 '22 12:09

Kirit Vaghela