且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过上下文操作栏获取在web视图中选择文本

更新时间:2022-04-15 06:56:36

您不能这样做,但与当前的API。

You can't do that yet with the current API.

我针对这个功能请求 - 发行24841:的WebView应允许应用程序来提供定制上下文操作栏http://$c$c.google.com/p/android/issues/detail?id=24841

I filed a feature request for this - Issue 24841: WebView should allow applications to supply a custom Contextual Action Bar http://code.google.com/p/android/issues/detail?id=24841

基本上,在web视图4.0具有硬codeD自身的上下文操作栏(CAB)。该CAB具有参考回web视图,并与参考,它可以得到选定的文本。我不知道你是如何能够检测ActionMode起点和修改菜单,但如果你能做到这一切,那么你被卡住,因为getSelection()是封装和私营部门目前。我提出,作为一个单独的问题,并将其链接到previous问题上面。

Basically, WebView in 4.0 has hardcoded its own Contextual Action Bar (CAB). That CAB has a reference back to the WebView and with that reference, it can get the selected text. I'm not sure how you were able to detect the ActionMode starting and modify the menu, but if you were able to do all of that, then you are stuck because getSelection() is package-private currently. I filed that as a separate issue and linked it to the previous issue above.