允许在WebView中长按触摸事件选择文本

时间:2011-04-10 22:54:59

标签: android webview motion-detection

我是Java新手。我一直试图在长按或长按事件中允许在WebView中选择文本。我让它像这样工作,但它干扰了WebView的缩放功能。

有谁知道如何将MotionEvent更改为长按动作事件或类似的东西? 请记住,我是全新的:)

public boolean onTouchEvent(MotionEvent "ACTION_DOWN") {
    try {
        KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
                KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
        shiftPressEvent.dispatch(webview);
    } catch (Exception e) {
        throw new AssertionError(e);
    }
    return false;
}

2 个答案:

答案 0 :(得分:1)

您是否考虑过使用onLongClick?请参见View.setOnLongClickListener

希望这有帮助,

Phil Lello

答案 1 :(得分:1)

您可以使用registerForContextMenu()来检测longpress ..