从web视图捕捉导航事件 [英] capture navigation events from WebView

查看:187
本文介绍了从web视图捕捉导航事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个web视图,有装进去一些自定义的HTML。在此HTML有一个链接到一个图像。当用户点击该链接现在,它会自动打开默认的Andr​​oid浏览器的图像。我反而想捕获click事件,并在自己的视图中打开的URL,以在UI中preserve品牌。

I have a webview that has some custom HTML loaded into it. In this HTML there is a link to an image. Right now when the user clicks the link, it automatically opens the image in the default android browser. I would instead like to capture that click event and open the URL in my own view as to preserve branding within the UI.

在iOS的,这是通过使用UIWebViewDelegate做,有没有类似的东西了Android的WebView功能?

In iOS this is done by using a UIWebViewDelegate, is there something similar for android's WebView?

推荐答案

创建 WebViewClient 的子类,并覆盖 shouldOverrideUrlLoading()。然后,通过 setWebViewClient重视这个类的一个实例,以你的的WebView ()。这适用于简单的链接和服务器发出的重定向。

Create a subclass of WebViewClient and override shouldOverrideUrlLoading(). Then, attach an instance of that class to your WebView via setWebViewClient(). This works for simple hyperlinks and server-issued redirects.

这篇关于从web视图捕捉导航事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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