在一个web视图中选择文本? [英] Selecting text in a WebView?
本文介绍了在一个web视图中选择文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在浏览器中调用它隐藏在SDK中的WebView 公共无效emulateShiftHeld()
办法做到这一点。
任何其他的选择吗?
The browser does this by calling public void emulateShiftHeld()
method on the WebView which is hidden in the SDK.
Any other options?
推荐答案
从扩展的类的的WebView 的:
public void selectAndCopyText() {
try {
Method m = WebView.class.getMethod("emulateShiftHeld", null);
m.invoke(this, null);
} catch (Exception e) {
e.printStackTrace();
// fallback
KeyEvent shiftPressEvent = new KeyEvent(0,0,
KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
shiftPressEvent.dispatch(this);
}
}
然后你必须使用的 ClipboardManager 的观看新的文本。
工作在Android 1.5 - 2.3。 <一href="http://developer.android.com/reference/android/webkit/WebView.html#emulateShiftHeld%28%29">emulateShiftHeld()由于2.2公之于众。
Works on Android 1.5 - 2.3. emulateShiftHeld() made public since 2.2.
这篇关于在一个web视图中选择文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文