Search code examples
androidandroid-spinnerandroid-toolbarcontextual-action-bar

Toolbar can still be interacted with in Contextual ActionBar


The Contextual ActionBar doesn't integrate with the toolbar, like it did with the ActionBar. It will appear above the toolbar. This can be fixed by placing

`<item `name="windowActionModeOverlay">true</item>` 

inside styles.xml

The problem is that while the CAB now overlays the toolbar, that's all it does. This means, that I can still interact with the toolbar when in action mode.

I have included a picture of the problem below. Here you can see that the spinner found on the toolbar, still comes up when I press area where the spinner is located on the toolbar.

enter image description here

Is there a way to fix this?


Solution

  • Solution

    hide the toolbar when actionmode is first created. Do not set View.GONE, as this will remove the space of the toolbar. Instead user View.INVISIBLE. This keeps the toolbar space.

    @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            getActivity().getMenuInflater().inflate(R.menu.contextual_action_bar, menu);
            toolbar.setVisibility(View.INVISIBLE);
    
            return true;
        }
    

    Make toolbar visible when action mode is destroyed.

    @Override
        public void onDestroyActionMode(ActionMode mode) {
            this.mActionMode = null;
            toolbar.setVisibility(View.VISIBLE);
        }