How to load webview links inside this same webview Android

后端 未结 1 1729
独厮守ぢ
独厮守ぢ 2021-01-14 04:53

I want to build a Android webApplication without PhoneGap, and i have a problem : when i click on a link it open the android default browser... : so how to load webview link

相关标签:
1条回答
  • 2021-01-14 05:44

    You have to intercept the URL links that your WebView might have in order to do your custom implementation.

    You have to create a WebViewClient for your WebView and then override the public boolean shouldOverrideUrlLoading(WebView view, String url) method to achieve such a thing.

    Sample code:

    //web view client implementation
    private class CustomWebViewClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
            //do whatever you want with the url that is clicked inside the webview.
            //for example tell the webview to load that url.
            view.loadUrl(url);
            //return true if this method handled the link event
            //or false otherwise
            return true;
        }
    }}
    
    //in initialization of the webview:
    ....
    webview.setWebViewClient(new CustomWebViewClient());
    ....
    

    Tell me if that helps.

    0 讨论(0)
提交回复
热议问题