Android action bar not showing overflow
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()); }}
Output
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
I realize this is not an overflow menu, but it is similar.Okay, this is simple but was hard to figure out.
You first need a menu item you want to use as the overflow inflater. Example
<item android:id="@+id/a_More" android:icon="@drawable/more" android:showAsAction="always" android:title="More"> </item>
Once you have your item, add a sub-menu containing your items you want in the overflow menu. Example:
<item android:id="@+id/a_More" android:icon="@drawable/more" android:showAsAction="always" android:title="More"> <menu> <item android:id="@+id/aM_Home" android:icon="@drawable/home" android:title="Home"/> </menu></item>
On click this will inflate other items within. My application is using ActionBarSherlock 4.0 so before this will work for you, you will need to access the "SplitActionBar". (Will still work on default android Actionbar)
Here's how:In your AndroidManifest.xml file, you need to add this code under the activity you need the overflow menu in.
android:uiOptions="splitActionBarWhenNarrow"
NOTE: Your item that inflates your overflow menu MUST showAsAction="always"
Vwola! you have an overflow menu! Hope I helped you out. :)