Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All icons of ActionMode Bar are not showing in Android?

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;
}

Output This image is my output which is showing only one icon of menu but i want all other icons too.

like image 823
Wahib Avatar asked Dec 14 '22 14:12

Wahib


1 Answers

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.

like image 150
andreid Avatar answered Dec 21 '22 10:12

andreid