8

In my app I'm using the Toolbar as explained in the official documentation (v7 appcompat support library, Theme.Appcompat.Light.NoActionBar, android.support.v7.widget.Toolbar, setSupportActionBar(myToolbar)): http://developer.android.com/training/appbar/index.html

I have an ExpandableListView and I'd like to implement the contextual action mode when I long-click on an item. To achieve this I use: setMultiChoiceModeListener(new MultiChoiceModeListener()). This way, however, the action mode bar is displayed at the top of the screen, pushing down the Toolbar (I think it's because the system uses the ordinary action mode, and not the support action mode). I want it to be displayed on the Toolbar.

I tried this solution:

windowActionBarOverlay = true

but it doesn't work.

Abhinav Gupta
  • 2,225
  • 1
  • 14
  • 30
iClaude
  • 163
  • 1
  • 9

3 Answers3

8

I had this problem as well.
The solution you tried was a bit off.

Instead of <item name="windowActionBarOverlay">true</item>

try setting <item name="windowActionModeOverlay">true</item>

in your App's theme. This will overlay the action mode bar over the toolbar as desired.

Chad Mx
  • 1,266
  • 14
  • 17
0

you can use this code in your adapter

 public boolean multiSelect = false;
private ArrayList<String> selectedItems = new ArrayList<>();
ActionMode modee;
private ActionMode.Callback actionModeCallbacks = new ActionMode.Callback() {
    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        multiSelect = true;
        menu.add("Delete");
        modee=mode;
        return true;
    }

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

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        for (int i = 0; i < selectedItems.size(); i++) {
            for (int j = 0; j < sizeOfdata; j++) {
                if (data.get(j).getFull_name() == selectedItems.get(i)) {
                    data.remove(j);
                    deleteContact(selectedItems.get(i));
                     //or your code 
                    break;
                } else {
                    // continue;
                }
            }
        }
        mode.finish();
        return true;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode) {
        multiSelect = false;
        selectedItems.clear();
        notifyDataSetChanged();
    }
};
Sultan
  • 119
  • 1
  • 12
0

This worked for me... If you are using custom toolbar, then instead of removing the default toolbar from manifest using android:theme="@style/Theme.Design.NoActionBar" try

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">  
   <item name="windowActionBarOverlay">true</item>
 </style> 

in styles and remove that code from Manifest file.

Burkely91
  • 902
  • 9
  • 28
Harsh
  • 1
  • 1