Is it possible to select the text from a webview then to copy and paste. Is there any special method to do this??Please help me..
问问题
9163 次
2 回答
3
希望对你有帮助...
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);
}
}
覆盖触摸事件
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);
}
}
于 2012-05-14T13:38:47.333 回答
1
根据某人博客的这个网站说“在Android 3.0及更高版本中默认情况下可以使用WebView中的复制功能”,并且可能这些信息可能会有所帮助,Android:如何从webview中选择文本
于 2013-03-03T12:08:21.560 回答