在一个web视图中选择文本?视图、文本、web

由网友(眉间上的悲痛)分享简介:在浏览器中调用它隐藏在SDK中的WebView 公共无效emulateShiftHeld()办法做到这一点。任何其他的选择吗?The browser does this by calling public void emulateShiftHeld() method on the WebView which is...

在浏览器中调用它隐藏在SDK中的WebView 公共无效emulateShiftHeld()办法做到这一点。 任何其他的选择吗?

The browser does this by calling public void emulateShiftHeld() method on the WebView which is hidden in the SDK. Any other options?

推荐答案

从扩展的类的的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 的观看新的文本。

工作在Android 1.5 - 2.3。 emulateShiftHeld()由于2.2公之于众。

Works on Android 1.5 - 2.3. emulateShiftHeld() made public since 2.2.

阅读全文

相关推荐

最新文章