Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 2.2 webview search problem

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.

like image 303
Brijesh Masrani Avatar asked Sep 13 '10 07:09

Brijesh Masrani


2 Answers

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){}
like image 88
Ilya Izhovkin Avatar answered Nov 12 '22 18:11

Ilya Izhovkin


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){}  
like image 42
jianwu_chen Avatar answered Nov 12 '22 18:11

jianwu_chen