Android: how to find in the WebView page displayed content

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Android : How to find the show in the WebView page content

Author : Aoyousatuo Zhao

WebViewIs one of the commonly used components provided by Android. It is designed to display the html file. Because of this, so in the development process of application we can through will need to display the contents of the html format String and thus easy to achieve various typesetting sorting into effect.

Although the WebView component has a lot of functions and provides convenience for application development, but owing to its open Co., sometimes this convenience will often cause great restraint to developers, for example, developers can not easily control the WebView display start line, can't get relevant information etc. So when WebView to facilitate the general public will inevitably exist many shortcomings.

I encountered a problem during the development and application of html: displays the content specified in the current screen. How to solve this problem? Methods we study WebView and open again and again, has not obtained the very good solution. White no, I came to the underworld, the official not, I will collect the romance, "all roads lead to Rome! So I have searched everywhere for the WebView source code, hope that through non conventional methods (method not open call in the WebView Class Library) improvement. It is very difficult. And obviously, even if found, it is not safe to call. Just as Shanghai building collapse, it collapsed to the ground. The road is bumpy, faces an uncertain future, and may be broken road.

ChangChun. I though the emperor but sometimes also very helpless, how to do? I once again reluctantly and look at WebView open the wretched method. Finally, wanted to think, they most likely came only findAll and findNext. So I think, if only to ensure need positioning content, through the search needs to locate content, not just the content displayed to the screen? So I want to start a try, when, after the success of celebrating.

However, I see a help document, the two method that is empty, so the hearts of indistinct a bit nervous. Indeed, test procedure, without any effect. I had to go to the consultation and two colonial minister Baidu and Google. Finally … … have the answer. The following letter world, you Ai Qing, listen carefully:

Look at the colonial Secretary to me saying:


Find is not a fully supported feature in webview.
However, try calling view.setFindIsUp(true) to get the match to draw; This function is hidden and subject to change, so your app may break in a future release.


WebView on the search function cannot fully support. However, we can try to call the setFindIsUp method to get the results of the query, and display it on the screen (draw out). This method is hidden and easy to change, so your application may in future versions can not normally use it.


Thus, to findAll and findNext functions, you must call the setFindIsUp method, but this method is the internal function, so the security can not be guaranteed, perhaps in a future version will be harmonious.

However, this is only a conservative one solution. Later, if not normal use, support method, perhaps WebView will have better.!


Example :

Assuming that WebView is loaded with the html content, the following is the search for part of the program:


WebView webView = (WebView)findViewById( ;

webView.findAll(“a”) ;


  Method m = WebView.class.getMethod(“setFindIsUp”, Boolean.TYPE) ;

  m.invoke(webView, true) ;

}catch(Throwable ignored)




findNextUse empathy, here no longer tired.




WebView findAll & findNext method must be used within the setFindIsUp class method.


findAllThe effect is hollow frame mark all the matching content, matching white first to search with a solid box, and will display the current screen.


If you need to cancel the search state, you can call the clearMatches method.


In addition, if the benefit from this article, please support me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Alexandra at November 14, 2013 - 8:30 PM