如何在Webview中实现自己的SelectAll,剪切,复制,粘贴

时间:2013-05-30 05:33:52

标签: android webview contextual-action-bar richeditabletext

我正在使用WebView实现Rich Edit Text,编辑器操作的按钮显示在上下文操作栏(CAB)中,长按webview它的默认CAB显示按钮,我理解Webview不提供任何规定定制它的CAB。

所以我认为最好实现选择,剪切,复制,粘贴操作。 我已经尝试this但是没有为我工作。

我的应用程序针对的是Android 3.x +设备。

请建议我如何做到这一点。

1 个答案:

答案 0 :(得分:3)

我使用BTAndroidWebViewSelection javascript库来执行此操作。对于剪切,复制和粘贴操作,我注入了自己的JavaScripts。

  • 全选 - (function () { document.execCommand('selectall', true, null);})()
  • 剪切 - (function () { document.execCommand('cut', true, null);})()
  • 复制 - (function () { document.execCommand('copy', true, null);})()
  • 粘贴 - document.execCommand('insertHtml', false,'" + text + "');文字是从ClipBoard复制的数据。

感谢。

相关问题