通过上下文操作栏获取在web视图中选择文本 [英] Getting selected text in a WebView via a contextual action bar

查看:168
本文介绍了通过上下文操作栏获取在web视图中选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据了解是<一个href="http://stackoverflow.com/questions/4892111/android-webview-javascript-getselection">difficult获得所选文本中的WebView,因为web视图文本的选择是由私有类,<一个实际处理href="http://stackoverflow.com/questions/6948447/android-3-0-webview-text-selection-javascript">WebTextView.

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.

不过,与最近发布的的Andr​​oid 4.0设计规范,似乎有实现的一线希望这种通过上下文的动作条(合格评定)。它

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:

只要你允许用户选择通过长preSS数据使用CAB的。可以控制一个CAB的行动内容,以便插入的动作你想用户能够执行

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.

我是misinter preting呢? 有没有办法通过一个CAB检索一个的WebView选定的文本?

Am I misinterpreting this? Is there a way to retrieve selected text from a WebView via a CAB?

经过长期的点击和文本选择模式开始,我目前可以检测当 ActionMode 启动和修改原始的复制/粘贴菜单;但是,我不能完全弄清楚如何真正地检索选定的文本。

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.

推荐答案

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

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

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

这篇关于通过上下文操作栏获取在web视图中选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆