方法介绍

在Android中使用自定义webview的时候,会重写shouldOverrideUrlLoading方法,如下:

public class MyWebViewClient extends WebViewClient {

@Override

public boolean shouldOverrideUrlLoading(final WebView view, final String url) {

// 父类默认返回false

return super.shouldOverrideUrlLoading(view,url);

}

}

下面就详细了解该方法的作用和使用。先看一下接口源码的注释和翻译:

@Deprecated

public boolean shouldOverrideUrlLoading(WebView view, String url) {

return false;

}

/**

* Give the host application a chance to take control when a URL is about to be loaded in the

* current WebView.

* 给宿主应用一个机会去控制在当前webview即将加载的一个url。

*

* If a WebViewClient is not provided, by default WebView will ask Activity

* Manager to choose the proper handler for the URL.

* 如果没有提供(自定义创建)WebViewClient,通过默认的webview会要求Activity Manager去处理当前URL。(补充:通常是系统浏览器)

*

* If a WebViewClient is provided,returning

* 如果提供了(自定义创建设计)WebViewClient

*

* {@code true} causes the current WebView to abort loading the URL, while returning

* 返回true会导致当前webview中止加载url,

*

* {@code false} causes the WebView to continue loading the URL as usual.

* 返回false会导致webview正常继续加载url。

*

* Do not call {@link WebView#loadUrl(String)} with the request's

* URL and then return {@code true}.

* 不要调用loadUrl方法并且返回true。

*

* The correct way to continue loading a given URL is to simply

* return {@code false}, without calling {@link WebView#loadUrl(String)}.

* 继续加载url的正确的做法就是简单的返回false即可,不需要调用loadUrl方法。

*/

public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {

相关链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: