Opening webview not in new browser

前端 未结 9 1773
走了就别回头了
走了就别回头了 2020-11-28 09:14

I am implementing a webview. I want two buttons on the top of the web page.

I have one vertical linear layout, inside of which is one horizontal layout with two but

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 09:36

    Adding the following code before loadUrl() will solve this problem,

    wv.setWebViewClient(new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
              view.loadUrl(url);
              return true;
               }}); 
    

    The shouldOverrideUrlLoading() from WebViewClient does this job. Here goes the Android doc for shouldOverrideUrlLoading,

    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...

    http://developer.android.com/reference/android/webkit/WebViewClient.html#shouldOverrideUrlLoading%28android.webkit.WebView,%20java.lang.String%29

提交回复
热议问题