Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start an action mode in android 3.0

We have this default feature in android 3.0 that when we long press somewhere (say in a webview) action mode is started and as a result the action bar changes with many default features like copy, find etc.

Now what I want is that I want to start this action mode but not by long pressing on the web view. I want that when I load a webview I want this action mode automatically started without any long press. Is it possible ? Is there any method by which we can achieve this?

like image 922
Ankit Avatar asked Dec 12 '22 07:12

Ankit


1 Answers

In case you still need it or other people are looking for it

startActionMode(mContentSelectionActionModeCallback);

And as callback use:

    private ActionMode.Callback mContentSelectionActionModeCallback = 
       new ActionMode.Callback() {
    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) 
    {
            //Here you can inflate a menu
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.name_menu, menu);

        return true;
    }

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

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

    public void onDestroyActionMode(ActionMode actionMode) {
        awesomeAdapter.overviewFragment.stopEdit();
    }
};
like image 135
QuirijnGB Avatar answered Jan 10 '23 06:01

QuirijnGB