Android Webview 中的文本选择

发布于 2025-01-01 17:13:06 字数 405 浏览 1 评论 0原文

在下面的代码中选择 Web 视图中的文本工作正常,

KeyEvent shiftPressEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0)                       
shiftPressEvent.dispatch(webView);

但该调度方法已被弃用。因此,我喜欢使用它

 public final boolean dispatch (KeyEvent.Callback receiver, KeyEvent.DispatcherState state, Object target) 

从上面的函数中给我一个想法来选择文本。

to select text in web view below code is working fine

KeyEvent shiftPressEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0)                       
shiftPressEvent.dispatch(webView);

but that dispatch method is deprecated. so instead of that i like to use this

 public final boolean dispatch (KeyEvent.Callback receiver, KeyEvent.DispatcherState state, Object target) 

give me an idea from the above function to select text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

身边 2025-01-08 17:13:06

我使用 javascript 接口在 2.2 - 4.0.3 中使用 Web 视图选择,该接口将所有触摸传递给它。该解决方案似乎工作得很好,我已经在 github 上放了一个示例项目。 github 项目在资产文件夹中包含必要的 js,以及加载测试页面并实现处理选择的所有必要方法的测试页面和 Web 视图。 github 项目的链接是 https://github.com/btate/BTAndroidWebViewSelection。努力吧。

I got web view selections working in 2.2 - 4.0.3 using a javascript interface that gets all touches passed to it. The solution seems to work pretty well and I've put an example project on github. The github project includes the necessary js in the assets folder as well as a test page and web view that loads the test page and implements all necessary methods to handle the selection. The link to the github project is https://github.com/btate/BTAndroidWebViewSelection. Have at it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文