I have a webview in my activity. Now when I use WebView.findAll()
method to search text in webview it is not highlighting the matching words.
It works fine in Android 1.6 but is not working in 2.2.
There is an issue in Android issue tracker about this: http://code.google.com/p/android/issues/detail?id=9018
I placed this code right after WebView.findAll()
, and it made highlighting working:
try
{
Method m = WebView.class.getMethod("setFindIsUp", Boolean.TYPE);
m.invoke(webView, true);
}
catch (Throwable ignored){}
In android 4.0.3, seems the setFindIsUp is a private method. So above code won't work. As getMethod() method won't return the private methods. Following is a work-around to call the private method which works for 4.0.3:
try{
//Can't use getMethod() as it's a private method
for(Method m : WebView.class.getDeclaredMethods()){
if(m.getName().equals("setFindIsUp")){
m.setAccessible(true);
m.invoke(view, true);
break;
}
}
}catch(Exception ignored){}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With