Android 2.2 webview search problem

后端 未结 2 1861
遥遥无期
遥遥无期 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: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){}  
    

提交回复
热议问题