Android 2.2 webview search problem

后端 未结 2 1856
遥遥无期
遥遥无期 2020-12-06 12:04

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 f

相关标签:
2条回答
  • 2020-12-06 12:29

    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){}
    
    0 讨论(0)
  • 2020-12-06 12:40

    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){}  
    
    0 讨论(0)
提交回复
热议问题