// the find
CarGuo/CustomActionWebView
自定义webview长按文本弹出选项,并且点击后返回选项与所选中的文本,你的webview不再只支持系统的复制等功能了,长按web文本实现文本一键收藏、分享,就是这么简单。Demo中附带对webView的详细使用:api详解,配置详解,js多种通信方式详解。
A small Android library that adds custom actions to the text-selection menu of a WebView. Long-pressing text on a page shows your items, and picking one returns the item title and the selected text to your code, which is enough to build a save-or-share flow without hand-writing the JavaScript bridge. Aimed at Android developers who already embed a WebView and want more than the system copy menu.
The API is close to a stock WebView: you set an action list, call linkJSInterface, and attach a listener that receives the title and the selected string. The library is a WebView subclass plus one listener interface, so it is quick to read in full before adopting it. The demo app also works as a reference for WebView configuration, lifecycle and memory-leak handling, and the different ways JavaScript can talk to Java, which is useful even if you never use the library.
The last push was December 2017, and the install snippet uses the deprecated compile configuration with a v1.0.1 tag, so expect to fork it or verify it against a current Android target yourself. The selection hook depends on the WebView action mode, which Android has changed across releases, and the repo has no tests to show what still works. The README code samples are cut off mid-identifier (for example setBuiltInZoomContro), so they will not compile as pasted and you will need to read the source to find the real calls.