I'm trying to recreate the "Find on page" function found in the android web browser so I can apply it to my webview.
Does anyone know a good place for me to start looking or any hints?
So far I have:
webView . findAll ("something"); try { Method m = WebView.class.getMethod ("setFindIsUp", Boolean.TYPE); m.invoke ( webView , true); } catch (Throwable ignored) { Log.i 开发者_开发百科("Error", ignored.toString ()); }
But it only allows for a predefined search. The browser allows you to type in something to search for.
I'm hoping there is some example to work off of. I can't imagine I'm the first to want to do this.
Any help is greatly appreciated!
showFindDialog works great but only for Android 3.x. Apparently, it doesn't work for android 4.x... For Android 2.x, use findall()
If your code already allows for a predefined search, all you need to do is get input from the user, and use the resulting String in place of the "something"
in your example.
Here's one possible method, using an AlertDialog: http://www.androidsnippets.com/prompt-user-input-with-an-alertdialog
If you use showFindDialog(queryString, true); on your webview all is done for you.
精彩评论