我在网络视图中有一些文字。我可以选择那些文字。我想强调那些文字,但我不知道该怎么做。有任何想法的人,请帮忙!感谢名单!
答案 0 :(得分:1)
你需要运行java脚本
public static String Highlightscript = " <script language=\"javascript\">" +
"function highlightSelection(){" +
"var userSelection = window.getSelection();" +
"for(var i = 0; i < userSelection.rangeCount; i++)"
+ " highlightRange(userSelection.getRangeAt(i));" +
"}" +
"function highlightRange(range){"+
"span = document.createElement(\"span\");"+
"span.appendChild(range.extractContents());"+
"span.setAttribute(\"style\",\"display:block;background:#ffc570;\");"+
"range.insertNode(span);}"+
"</script> ";
和
webView.loadUrl("javascript:highlightSelection()");
确保您启用了javascript
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
答案 1 :(得分:0)