开发者

capture navigation events from WebView

开发者 https://www.devze.com 2023-03-09 15:09 出处:网络
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 clic开发者_如何学Cks the link, it automatically opens the image in the defaul

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 clic开发者_如何学Cks 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.

In iOS this is done by using a UIWebViewDelegate, is there something similar for android's 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消