Android的web视图shouldOverrideUrlLoading方法 [英] Android Webview shouldOverrideUrlLoading method

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

问题描述

当是 shouldOverrideUrlLoading 调用的方法?

  webView.setWebViewClient(新WebViewClient(){
    @覆盖
    公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){


    }
});
 

  1. 是它的URL的初始加载过程中调用?例如 webView.loadUrl(文件:///android_asset/html/index.html);
  2. 在它被称为每次中的WebView改变网址?

任何参考?我一个也没找到。谢谢

解决方案
  1. 但它确实,被调用时的WebView从一个用户曾要求加载不同的URL。

  2. 调用使用loadURL()也将触发 shouldOverrideUrlLoading()方法。 (只有当一个新的URL即将被载入。)

  

给主机应用程序有机会接管控制,当一个新的URL是关于当前的WebView加载。如果   WebViewClient不提供,默认的WebView会问活动   管理器来选择适当的处理程序的URL。如果WebViewClient是   前提是,返回true表示主机应用程序处理的URL,   而返回false表示目前的WebView处理的URL。

编号:<一href="http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading%28android.webkit.WebView,%20java.lang.String%29"相对=nofollow>公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)

When is shouldOverrideUrlLoading method called?

webView.setWebViewClient(new WebViewClient(){
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {


    }
});

  1. Is it called during initial loading of url? e.g. webView.loadUrl( "file:///android_asset/html/index.html");
  2. Is it called everytime URL of webview changes?

Any reference? I didn't find one. Thanks

解决方案

  1. It does however, get called when the WebView to load a different URL from the one the user had requested.

  2. Calling loadUrl() will also trigger the shouldOverrideUrlLoading() method. (Only when a new url is about to be loaded.)

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.

Ref : public boolean shouldOverrideUrlLoading (WebView view, String url)

这篇关于Android的web视图shouldOverrideUrlLoading方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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