How to run action mode in android 3.0

We have this feature by default in Android 3.0, when we long press somewhere (say, in web page view mode), and as a result, the action bar changes with many standard functions, such as copying, searching, etc.

Now I want to start this mode, but not a long press on the web view. I want that when loading webview I want this action mode to automatically start without any long press. Is it possible? Is there any way we can achieve this?

+4
source share
1 answer

If you still need it or other people are looking for it

startActionMode(mContentSelectionActionModeCallback); 

And how to use a callback:

  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(); } }; 
+13
source

Source: https://habr.com/ru/post/1384901/


All Articles