I have created a menu for my actionmode bar with icons but not all menu are showing with icon in actionmode bar. This is my menu xml file.
<?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/menu_archive"
android:icon="@drawable/ic_action_file_archive"
android:orderInCategory="100"
android:title="@string/action_remove"
app:showAsAction="always" />
<item
android:id="@+id/menu_upload_to_cloud"
android:icon="@drawable/ic_action_file_cloud_upload"
android:orderInCategory="200"
android:title="@string/action_upload_to_cloud"
app:showAsAction="always" />
<item
android:id="@+id/menu_delete"
android:icon="@drawable/ic_action_file_delete"
android:orderInCategory="300"
android:title="@string/action_move_to_trash"
app:showAsAction="always" />
</menu>
This is my code for creating Actionmode Bar.
@Override
public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.menu_actionmode_device_documents, menu);
return true;
}
@Override
public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) {
}
@Override
public void onDestroyActionMode(android.support.v7.view.ActionMode mode) {
this.actionMode = null;
}
This image is my output which is showing only one icon of menu but i want all other icons too.
This may be a little too late, but I'm putting this answer in case someone else runs into the same problem. It seems the system does not keep count of the app:showAsAction="always"
attribute.
The soulution is to update the menus manually in onPrepareActionMode
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
menu.findItem(R.id.menu_archive).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.findItem(R.id.menu_upload_to_cloud).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
menu.findItem(R.id.menu_delete).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
This seems odd but it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With