this solution provided by ban-geoengineering is one very intresting...
3 dot icon sometimes doesn't display if you use android:showAsAction
namespace android: instead custom namespace like:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/taskNotificationsBtn"
app:showAsAction="always"
android:icon="@drawable/tasks"/>
But solution provided by ban-geoengineering help me to solve problem with reversing ActionBar items direction to match this to Arabic layout. I have used ActionBarRTLizer library and standard approach with android os 3dots causes some bug when menu item icons cover each other sometimes (very frustratign situation), but this custom solution
<item
android:id="@+id/empty"
android:title="@string/options"
android:orderInCategory="101"
android:showAsAction="always"
android:icon="@drawable/ic_action_overflow">
<menu>
<item android:id="@+id/action_settings"
android:icon="@android:drawable/ic_menu_preferences"
android:showAsAction="ifRoom"
android:title="@string/settings" />
<item android:id="@+id/action_help"
android:icon="@android:drawable/ic_menu_help"
android:showAsAction="ifRoom"
android:title="@string/help" />
</menu>
</item>
solved the problem and RTL works perfectly well! :)
This may also be helpful if you want to handle hardware menu buttons:
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_MENU) {
// do stuff
return true;
} else {
return super.onKeyUp(keyCode, event);
}
}
and add here:
mMenuReference.performIdentifierAction(R.id.menu_0, 1);
in order to replace Sub Menu displayed as overflow menu depending for example on current Activity you could use this solution:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate your main_menu into the menu
getMenuInflater().inflate(R.menu.main_menu, menu);
// Find the menuItem to add your SubMenu
MenuItem myMenuItem = menu.findItem(R.id.my_menu_item);
// Inflating the sub_menu menu this way, will add its menu items
// to the empty SubMenu you created in the xml
getMenuInflater().inflate(R.menu.sub_menu, myMenuItem.getSubMenu());
}