3

I've discovered a strange problem while try to implement ListView with multichoice mode. I use CHOICE_MODE_MULTIPLE_MODAL to turn on multichoice mode, and MultiChoiceModeListener to provide action mode menu and handle events. Here is my code:

    ListView listView = (ListView) findViewById(R.id.list);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.item,
            new String[] {"111", "222", "333", "444", "555"});
    listView.setAdapter(adapter);

    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
        @Override
        public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {
        }

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            MenuInflater inflater = actionMode.getMenuInflater();
            inflater.inflate(R.menu.my_menu, menu); // my_menu is just stub empty menu
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {
        }
    });

It works fine, I can select my list items and action mode appears: screenshot. The problem is that when I rotate my device and then close action mode by pressing back button, sometimes (not every time) the action bar becomes ugly, with strange light background: screenshot

It is reproducing on my device with Android 5.0. The code is quite easy, and I don't think that it is bug in my code. Maybe, it is internal bug in Android system? Did anyone face this problem? Thanks in advance!

1 Answers1

0

You should force the ActionBar to redraw itself. Check my answer here:

https://stackoverflow.com/a/53997778/3185295

Nikolai
  • 821
  • 3
  • 17
  • 22