Reputation: 676
Is there any way to restore a default WebViewClient
in WebView
?
There is a WebView.setWebViewClient(WebViewClient client)
method, but no get
companion.
I would like to to load URL in WebView and avoid being sent to native browser in case of redirections but then go back to default behavior - links clicked opening in native browser.
To achieve that I would like set my own WebViewClient temporarily and then restore the default one.
WebView webView = new WebView(this);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("http://example.com");
// TODO: restore default WebViewClient
Upvotes: 0
Views: 1514
Reputation: 676
Finally the code:
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
webView.setWebViewClient(null);
}
});
webView.loadUrl(url);
Upvotes: 0
Reputation: 3231
to go back to the default behavior try:
webview.setWebViewClient(null);
however you can't do that immediately after you call loadUrl, you need to at least wait for WebViewClient.onPageFinished.
Upvotes: 1