It's known to be difficult to get selected text in a WebView because WebView text selection is actually handled by a private class, WebTextView.
However, with the recently released Android 4.0 Design guidelines, there seems to be a glimmer of hope of achieving this through contextual action bars (CABs). It says:
Use CABs whenever you allow the user to select data via long press. You can control the action content of a CAB in order to insert the actions you would like the user to be able to perform.
Am I misinterpreting this? Is there a way to retrieve selected text from a WebView via a CAB?
After a long click and text selection mode begins, I can currently detect when the ActionMode
starts and modify the original copy/paste Menu
; however, I can't quite figure out how to actually retrieve the selected text.
ActionMode.Callback
, but that won't display the text selection cursors. – TabbithaActionMode
other than text selection. I override thepublic ActionMode onWindowStartingActionMode (ActionMode.Callback callback)
on the activity. Sayreturn super.onWindowStartingActionMode(new MyActionModeCallback());
. It work and the cursors do not disappear. However, I don't know what side-effect this workaround would cause. I can think of it is not system want us to do. – Autonomic