Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
603 views
in Technique[技术] by (71.8m points)

search - Android - Highlight text in WebView above android version 4.0.3

I have a webview that performs a search, this code works great for below android version 4.0.3, at this version and higher the highlight function fails to highlight. The search itself works and jumps the page around but nothing is shown for the result (Unless you look hard enough!).

I want to know if anyone knows of a work-around that supports higher than 4.0.3?

People in other answers have linked to these webpages as possible solutions but I am not sure how to adapt this to my webview in Android.

WebPages:

http://4umi.com/web/javascript/hilite.php#thescript
http://www.nsftools.com/misc/SearchAndHighlight.htm

Code I am using currently to search and highlight:

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && ((keyCode == KeyEvent.KEYCODE_ENTER))) {
                wv.findAll(findBox.getText().toString());

                try {
                    Method m = WebView.class.getMethod("setFindIsUp",
                            Boolean.TYPE);
                    m.invoke(wv, true);
                } catch (Exception ignored) {
                }
            }
            return false;
        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In Android 4.1(jellybean), WebView.findAll() is deprecated, we should use WebView.findAllAsync instead.

reference

Wish this help:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...