Sai
Sai

Reputation: 15718

How to Add android menu overflow icon in my app

How to add Action overflow button manually on Layout.xml and when user click the button it should do some other task other than opening menu button.

Menu Overflow

Upvotes: 3

Views: 769

Answers (2)

TharakaNirmana
TharakaNirmana

Reputation: 10353

Call this method inside onCreate():

   private void getOverflowMenu() {

        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) {
           e.printStackTrace();
       }
     }

Upvotes: 0

uncannyj
uncannyj

Reputation: 306

The overflow icon only appears if the device doesn't have a hardware menu button and when you have an item in your menu.xml that looks like this,

<menu xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        android:title="@string/action_settings"/>
</menu>

android:showAsAction="never" will always add the item to the options menu or the overflow (depending on the device). It is a builtin in android given the condition stated above.

Upvotes: 2

Related Questions