Search code examples
androidandroid-actionbaroverflow-menu

Adding overflow menu in actionbar android


I want to display overflow menu in android actionbar. In all device i need same design app name at left side of actionbar and overflow icon at right side with menu in it. Currently when i run app menu are showing on clicking of menu icon. I just want to show menu like attached image- enter image description here

below is my code inside menu.xml -

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/menu_red"
    android:orderInCategory="1"
    android:showAsAction="never"
    android:title="@string/news"/>
<item
    android:id="@+id/menu_green"
    android:orderInCategory="2"
    android:showAsAction="never"
    android:title="@string/online_test"/>

how to show menu in such way.

Thanks in advance.


Solution

  • <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item>
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="always"
        <menu>
    
            <item
                android:id="@+id/menu_red"
                android:title="red"/>
            <item
                android:id="@+id/menu_green"
                android:title="green"/>
        </menu>
    
    </item>
    

    this worked for me maybe work for you too