Action mode submenu and checkableBehavior

292 views Asked by At

I have a strange issue with submenus and android:checkableBehavior="single". It works fine if the menu is in action bar, but displays check boxes instead of radio buttons if menu is in the action mode. I use AppCompatActivity and create action mode with startActionMode().

menu xml:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/priority"
        android:title="@string/priority"
        app:showAsAction="ifRoom">

        <menu>
            <group android:checkableBehavior="single">
                <item
                    android:id="@+id/low_priority"
                    android:title="@string/low_pririty"/>
                <item
                    android:id="@+id/normal_priority"
                    android:title="@string/normal_priority"/>
                <item
                    android:id="@+id/high_priority"
                    android:title="@string/high_priority"/>
            </group>
        </menu>
    </item>
</menu>

How can I fix this?

1

There are 1 answers

2
Rolf ツ On BEST ANSWER

You menu works fine for me using the startSupportActionMode method instead of the startActionMode method. The startActionMode method should not be used when using the support library AppCompatActivity.

.startSupportActionMode(new android.support.v7.view.ActionMode.Callback() {
            @Override
            public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) {
                MenuInflater inflater = mode.getMenuInflater();
                inflater.inflate(R.menu.test_menu, 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) {
                return false;
            }

            @Override
            public void onDestroyActionMode(android.support.v7.view.ActionMode mode) {

            }
        });