October 2018
Intermediate to advanced
464 pages
15h 17m
English
If you want more control over the page navigation, you can create your own WebViewClient class. If you want to only allow links within your own website, override the shouldOverrideUrlLoading() callback as shown here:
private class mWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (Uri.parse(url).getHost().equals("www.packtpub.com")) { return false; //Don't override since it's the same host } else { return true; //Stop the navigation since it's a different //site } }}
Then, use the following code to set the client:
webview.setWebViewClient(new mWebViewClient());