Android WebView开发(三)--WebViewClient 与WebChromeClient的使用

本文详细介绍了Android WebView开发中的关键组件WebViewClient和WebChromeClient的使用,包括它们的作用、常用方法及实际应用场景。WebViewClient主要用于处理请求事件,如shouldOverrideUrlLoading方法用于控制URL加载。WebChromeClient则辅助处理Javascript对话框、网站图标等,onProgressChanged方法可获取网页加载进度。此外,还讨论了不同API版本下的兼容性问题和错误处理策略。
摘要由CSDN通过智能技术生成

1.前言

前两篇我们讲解了
Android WebView开发(一)–WebView的使用介绍
Android WebView开发(二)–WebSettings使用详解
想要了解的可以去看看。
今天是WebView开发的第三篇–WebViewClient 与WebChromeClient的使用。

2.WebViewClient类

2.1 WebViewClient作用:

WebViewClient主要用来处理请求事件和在合适的时候回调进行一些逻辑处理

2.2 WebViewClient 常用方法 :

2.2.1 shouldOverrideUrlLoading()方法

1.作用:

/**
     * Give the host application a chance to take over the control when a new
     * url is about to be loaded in the current WebView. If WebViewClient is not
     * provided, by default WebView will ask Activity Manager to choose the
     * proper handler for the url. If WebViewClient is provided, return true
     * means the host application handles the url, while return false means the
     * current WebView handles the url.
     * This method is not called for requests using the POST "method".
     *
     * @param view The WebView that is initiating the callback.
     * @param url The url to be loaded.
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AnjoyZhang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值