質問

Does Android provides text selection listener in WebView? For example, user select text in web view. Selected text will be shown in toast. If there is no such listener, how to implement this idea in other ways?

PS. Please note that I do not mean copying or some action modes.

役に立ちましたか?

解決

As far as I know, WebView handles text selection internally and does not provide any listeners regarding this.

The selection is updated when user moves the cursor on the web page. One possible way to achieve your goal, is to call WebViewClassic.getSelection() whenever user moves the cursor during text selection. Since this is not a public API, you may need to utilize Java Reflection.

So you may also need to override onTouchEvent(), in your App to decide whether user has entered selection mode and especially when s/he moves the cursor. If yes, calling WebViewClassic.getSelection() will result in a string of what has been selected.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top