Clicking URLs opens default browser

前端 未结 6 528
独厮守ぢ
独厮守ぢ 2020-11-22 13:09

I have loaded an external URL in my WebView. Now what I need is that when the user clicks on the links on the page loaded, it has to work like a normal browser

6条回答
  •  感动是毒
    2020-11-22 13:19

    Official documentation says, click on a link in a WebView will launch application that handles URLs. You need to override this default behavior

        myWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });
    

    or if there is no conditional logic in the method simply do this

    myWebView.setWebViewClient(new WebViewClient());
    

提交回复
热议问题