Android – How to show Overflow Menu Items to Action Bar in Android

androidandroid-actionbar

I am writing an Android App in which i am trying to show Overflow Menu Items to ActionBar

using this great tutorial link: http://wptrafficanalyzer.in/blog/adding-action-items-and-overflow-menu-items-to-action-bar-in-android/

Problem:

Not getting Overflow Menu Items (Icon)

Please see below Screen Shot for more clarity:
enter image description here

Manifest.xml:

<uses-sdk android:minSdkVersion="14" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" 
        android:uiOptions="splitActionBarWhenNarrow"              
        >

items.xml:

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

<item
    android:id="@+id/computer"
    android:title="@string/computer"
    android:icon="@drawable/computer"
    android:showAsAction="ifRoom|withText"
/>

<item
    android:id="@+id/gamepad"
    android:title="@string/gamepad"
    android:icon="@drawable/gamepad"
    android:showAsAction="ifRoom|withText"
/>

<item
    android:id="@+id/camera"
    android:title="@string/camera"
    android:icon="@drawable/camera"
    android:showAsAction="ifRoom|withText"
/>

<item
    android:id="@+id/video"
    android:title="@string/video"
    android:icon="@drawable/video"
    android:showAsAction="ifRoom|withText"
/>

<item
    android:id="@+id/email"
    android:title="@string/email"
    android:icon="@drawable/email"
    android:showAsAction="ifRoom|withText"
/>
 </menu>

I am using this tutorial, and trying to make Figure 6 : Action items and Overflow menu in Split Action Bar

Please help me to show Overflow Menu Items (ICON) to ActionBar

Now whenever i do click on Menu Button in emulator, then i am getting rest Menu Items….

Best Answer

Just to say that If your device has a menu-button, the overflow-icon won't show, on the newer phones the overflow button will show. I would not reccomend ASMUIRTI's answer since it is an awful hack that breaks consistency with the rest of the apps on the platform.

you must use

android:showAsAction="never"

and let the android device decide if the overflow menu is needed for that device.

Related Topic