Search code examples
androidwebviewmotion-detection

allow text selection on long press touch event in WebView


I am really new at Java. I have been trying to allow text selection in a WebView on a long press or long touch event. I have it working like this, but it is interfering with the zoom functions of the WebView.

Does anyone know how to change MotionEvent to a long press motion event or anything similar? Keep in mind I am completely new :)

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;
}

Solution

  • Have you looked into using onLongClick instead? See View.setOnLongClickListener

    Hope this helps,

    Phil Lello