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?

有帮助吗?

解决方案

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();
    }
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top