3

I want to implement my own custom view (not inflating a menu item), I'm planning to use a toolbar to appear each time contextMenu starts, and hide it when finished.

the problem is: there are only answer showing HOW to clear/inflate another menu over the default actionMode menu

what i`ve tried so far:

-> Use a custom contextual action bar for WebView text selection

Overriding the callback at the WebView

  @Override
    public ActionMode startActionMode(ActionMode.Callback callback) {
        callback2 = new customCallBack();
        return super.startActionMode(callback2);
    }



 public class customCallBack implements ActionMode.Callback {

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

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

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {

        }
    }

changing the return false to true, doesn't result in the desired behavior i.e. hide the cab

Overriding the OnLongClick is not a option too, since it disable the current selection.

Community
  • 1
  • 1
user2582318
  • 1,607
  • 5
  • 29
  • 47
  • I'm tying to figure out the same thing. I went through the same thought process as you. It's crazy that there is no simple way to do this – AlexW.H.B. Jun 01 '16 at 22:42

2 Answers2

2

This answer solves the problem: android webview: prevent text selection actionMode actionBar

not the most elegant solution ever, but I just tested it in an app I'm building and it works like a charm.

Community
  • 1
  • 1
AlexW.H.B.
  • 1,781
  • 3
  • 25
  • 50
1

The Only way that worked for me (only on on Android L+) is clearing all the menu items from context actionbar from the activity

 @Override
public void onActionModeStarted(ActionMode mode) {
    if (mActionMode == null) {
        mActionMode = mode;
        Menu menu = mode.getMenu();
        // Remove the default menu items (select all, copy, paste, search)
        menu.clear();
    }
    Toast.makeText(this, "onActionModeStarted", Toast.LENGTH_SHORT).show();
    super.onActionModeStarted(mode);

}

 @Override
    public void onActionModeFinished(ActionMode mode) {
        mActionMode = null;
        Toast.makeText(this, "onActionModeFinished", Toast.LENGTH_SHORT).show();
        super.onActionModeFinished(mode);
    }

inspired by Use a custom contextual action bar for WebView text selection

Also I wasn't able to implement the custom menu usin popupWindow or dialogs or dialog fragments.

So simply put it with the webView in a frame layout and play with its visability and margin

Mohammad Yahia
  • 483
  • 9
  • 19