且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android WebView,如何在应用程序中处理重定向而不是打开浏览器

更新时间:2022-11-18 14:03:09

创建一个 WebViewClient,并覆盖 shouldOverrideUrlLoading 方法.

Create a WebViewClient, and override the shouldOverrideUrlLoading method.

webview.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url){
        // do your handling codes here, which url is the requested url
        // probably you need to open that url rather than redirect:
        view.loadUrl(url);
        return false; // then it is not handled by default action
   }
});