问题描述
我需要得到的WebView选定的文本,可以选择永久突出显示文本。我想作为选择文本,虽然我试图使用剪贴板来获取文本它显示我在clipboard.getText()空指针异常。我曾尝试code为
I need to get the selected text from webview and have to highlight the text permanently. I tried as selecting the text and while i am attempting to get the text using clipboard it showing me null pointer exception at "clipboard.getText()". I have tried code as
ClipboardManager mClipboard =
(ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
KeyEvent shiftPressEvent = new KeyEvent(0, 0, KeyEvent.ACTION_DOWN,
KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(webview);
if(mClipboard!=null)
{
String text = mClipboard.getText().toString();
Toast.makeText(this, "select_text_now "+text, Toast.LENGTH_LONG).show();
}
我需要选定文本高亮futher..please帮助我..
I need to get the selected text for highlight futher..please help me..
推荐答案
我已经提交了错误的Android为此:的。如果你看一下车票,你会看到一些不同的解决方法。
I have filed an Android bug for this: Issue 24842: WebView should make getSelection public. If you look at the ticket, you'll see some various workarounds.
请注意,您张贴了code是大致相同emulateShiftHeld这是pcated在4.0代$ P $,这可能是为什么它是工作在2.2而不是4.0。
Note that the code you posted is roughly similar to emulateShiftHeld which is deprecated in 4.0, which is probably why it is working in 2.2 and not in 4.0.
这篇关于如何获得在Android中的WebView选定的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!