【问题标题】:Selecting text in a WebView and capture the spans在 WebView 中选择文本并捕获跨度
【发布时间】:2012-07-26 16:13:35
【问题描述】:

我的问题不言自明。我希望不仅能够在 WebView 中选择文本时捕获文本,而且还希望能够捕获文本周围的跨度。有没有办法在本地做到这一点?

【问题讨论】:

    标签: android webview html textselection


    【解决方案1】:

    1 - 在 WebView 中选择文本

    来自扩展 WebView 的类:

    public void selectAndCopyText() {
        try {
            Method m = WebView.class.getMethod("emulateShiftHeld", null);
            m.invoke(this, null);
        } catch (Exception e) {
            e.printStackTrace();
            // fallback
            KeyEvent shiftPressEvent = new KeyEvent(0,0,
                 KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
            shiftPressEvent.dispatch(this);
        }
    }
    

    然后您必须使用 ClipboardManager 来查看新文本。

    本教程可以帮助您。

    Selecting Text with a WebView

    2 - 捕获跨度

    这可以帮助你。

    How To Get WebView Content Into Bitmap?

    谢谢。

    【讨论】:

      猜你喜欢
      • 2011-01-15
      • 2010-11-09
      • 2017-05-16
      • 1970-01-01
      • 2011-11-21
      • 1970-01-01
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多