Enable copy and paste in webview android

Is it possible to select text from webview, then copy and paste. Is there any special method for this? Please help me..

+6
source share
2 answers

Hope this helps you ...

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

override touch events

 private void emulateShiftHeld(WebView view) { try { KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0); shiftPressEvent.dispatch(view); Toast.makeText(this, "select_text_now", Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.e("dd", "Exception in emulateShiftHeld()", e); } } 
+3
source

According to this blog site , someone says: “Copy function in WebView is available by default in Android 3.0 and higher”, and this information may be useful, Android: how to select text from a website

+1
source

Source: https://habr.com/ru/post/915675/


All Articles