Search code examples
androidandroid-actionbarandroid-toolbar

How to replace the overflow icon with text button like "MORE"


I'm trying to replace the standard three dot overflow icon with a text button like "More Pizza", so that users will see the option easily. Any help is greatly appreciated.


Solution

  • option_menu.xml

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        <item
            android:id="@+id/file"
            android:title="main"
            app:showAsAction="always">
            <!-- "file" submenu -->
            <menu>
                <item
                    android:id="@+id/create_new"
                    android:title="subitem1" />
                <item
                    android:id="@+id/open"
                    android:title="subitem2" />
            </menu>
        </item>
    </menu>
    

    In Activity this below code is of Kotlin don't worry if you using java, Android studio will do it for you. :)

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
            val inflater = menuInflater
            inflater.inflate(R.menu.option_menu, menu)
            return true
    
        }