GhostFlying
GhostFlying

Reputation: 819

How to disable ActionMode in SearchView

When user selects text in SearchView, the ActionMode will appear and show 2 tabs on the top, it seems ugly.

I tried some apps from Google like Gmail, inbox, Messenger, they disable the function, but how did they do? I tried to set the style, but failed.

Here is an example of Google IO 2014

enter image description here

Upvotes: 1

Views: 989

Answers (1)

Mattia Maestrini
Mattia Maestrini

Reputation: 32790

You can try this:

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void disableActionMode(SearchView searchView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        ((EditText) searchView.findViewById(R.id.search_src_text)).setCustomSelectionActionModeCallback(new 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) {

            }
        });
    }
}

Upvotes: 2

Related Questions