安卓:在果冻豆一的WebView编程方式触发文本选择模式 [英] Android: Programatically trigger text selection mode in a WebView on Jelly Bean

查看:273
本文介绍了安卓:在果冻豆一的WebView编程方式触发文本选择模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式触发文本选择模式的web视图,但code我已经使用并没有对果冻豆?

I need to programatically trigger text selection mode in a WebView, but the code I have used does not work on Jelly Bean?

我一直在使用下面的code,但它不再因为WebView.selectText,emulateShiftHeld,关键调度不再对果冻豆的支持。在Android 4.1(果冻豆)的作品

I have been using the following code but it no longer works on Android 4.1 (Jelly Bean) because WebView.selectText, emulateShiftHeld, and the key dispatch are no longer supported on Jelly Bean.

随着code上的所有版本到ICS是基于作品:<一href="http://stackoverflow.com/questions/7581131/how-to-enable-the-default-highlight-menus-in-android-webview">How使Android中的WebView默认亮点菜单?

Following code that works on all versions up to ICS is based on: How to enable the default highlight menus in android webview?

public void selectAndCopyText() {
    try {
        // ICS
            WebView.class.getMethod("selectText").invoke(this);
        } catch (Exception e1) {
        try {
            Method m = WebView.class.getMethod("emulateShiftHeld", (Class[])null);
            m.invoke(this, (Object[])null);
        } catch (Exception e2) {
            // fallback
            KeyEvent shiftPressEvent = new KeyEvent(0,0,
                     KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
            shiftPressEvent.dispatch(this);
        }
    }
}

我如何实现对果冻豆?

How do I implement similar functionality that works on Jelly Bean?

推荐答案

我列在这里评论一个潜在的解决方案:<一href="http://stackoverflow.com/questions/7581131/how-to-enable-the-default-highlight-menus-in-android-webview">How使Android中的WebView默认亮点菜单?

I have listed a potential solution in the comments here: How to enable the default highlight menus in android webview?

下面是潜在的解决方案的内容: 经过分析 android.webkit.WebViewClassic 我曾与下面的一些成功:

Here is the content of the potential solution: After analyzing android.webkit.WebViewClassic I have had some success with the following:

KeyEvent enterEvent = new KeyEvent(0,0,KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_ENTER,0,0);
enterEvent.dispatch(this); 

我想更多的可能需要,因为我需要向下滚动的WebView 之前,上述使用仿真器时的工作,但一点点真正的豆形软糖设备上测试后,上面似乎很好地工作。

I thought more might be required as I needed to scroll down the WebView a little before the above worked when using an emulator, but after testing on a real JellyBean device the above seems to work fine.

这篇关于安卓:在果冻豆一的WebView编程方式触发文本选择模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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