Android - 在 android 版本 4.0.3 以上的 WebView 中突出显示文本 [英] Android - Highlight text in WebView above android version 4.0.3

查看:30
本文介绍了Android - 在 android 版本 4.0.3 以上的 WebView 中突出显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行搜索的 webview,此代码适用于 android 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!).

我想知道是否有人知道支持高于 4.0.3 的解决方法?

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

其他答案中的人已将这些网页链接为可能的解决方案,但我不确定如何将其调整到我在 Android 中的 webview.

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.

网页:

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;
        }

推荐答案

在 Android 4.1(jellybean) 中,WebView.findAll() 已被弃用,我们应该使用 WebView.findAllAsync代替.

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

参考

希望对您有所帮助:)

这篇关于Android - 在 android 版本 4.0.3 以上的 WebView 中突出显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆