Web Browser Is Not Showing Anything
Solution 1:
Replace
mWebView.setWebViewClient(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
mWebView.loadUrl("https://google.com");
returntrue;
}
});
With
mWebView.setWebViewClient(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
returnfalse;
}
});
Give the host application a chance to take control when a URL is about to be loaded in the current WebView. If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a WebViewClient is provided, returning true causes the current WebView to abort loading the URL, while returning false causes the WebView to continue loading the URL as usual.
Solution 2:
So far from what I can tell you are supposed to extend the WebViewClient class with a separate class:
privateclassMyBrowserextendsWebViewClient {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
returntrue;
}
}
and then set it to the WebViewClient:
mWebView.setWebViewClient(newMyBrowser());
Also try adding settings for loading images automatically, enabling javascript and setting scrollbar:
@OverridepublicbooleanonNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
mWebView.getSettings().setLoadsImagesAutomatically(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
case R.id.navigation_home:
mWebView.loadUrl("https://yahoo.com");
returntrue;
case R.id.navigation_dashboard:
mWebView.loadUrl("https://google.com");
returntrue;
case R.id.navigation_notifications:
mWebView.loadUrl("https://apple.com");
returntrue;
}
returnfalse;
}
Solution 3:
if you are using android 8+ then you must have to do 2 things.
Add this
android:usesCleartextTraffic="true"
attribute in manifest application tag. AndroidManifest.xmlyou should override this method.
mWebView.setWebViewClient(newWebViewClient() { @OverridepublicbooleanshouldOverrideUrlLoading(WebView view, WebResourceRequest request) { view.load(request.getUrl().toString()) returntrue; } });
Solution 4:
mWebView.setWebViewClient(newWebViewClient() {
@OverridepublicbooleanshouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
mWebView.loadUrl("https://facebook.com");
returntrue;
}
});
Post a Comment for "Web Browser Is Not Showing Anything"