I'm loading my Webview from a text string, like so:
String encodedHtml = Base64.encodeToString(unencodedHtml.getBytes(), Base64.NO_PADDING);
webview.loadData(encodedHtml, "text/html", "base64");
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
I'd like to add a color Highlight option to the Menu, when the user long press a word. I've searched many other similar questions on StackOverflow without success. Your help with some sample code would be much appreciated. Thanks in advance!
UPDATE: I'm using this script to highlight:
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:inline;background:#ffc570;\");"+
"range.insertNode(span);}"+
"</script> ";