Reputation: 15718
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.
Upvotes: 3
Views: 769
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
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