In this blog,
We have shown you how to add the progress dialog while the Webview loads the URL.
Webview: A View that displays web pages. This class is the basis upon which you can roll your own web browser or simply display some online content within your Activity.
It uses the WebKit rendering engine to display web pages and includes methods to navigate forward and backward through a history, zoom in and out, perform text searches and more.
How to load the URL in Webview
1 2 3 4 |
WebView mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebViewClient(new myWebViewClient()); mWebView.loadUrl("https://mobikul.com/blog/"); |
Webview client,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
private class myWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.proceed(); } @Override public void onPageStarted(WebView view, String url, Bitmap facIcon) { //SHOW LOADING IF IT ISNT ALREADY VISIBLE progress = ProgressDialog.show(PaymentWebViewActivity.this, null, getResources().getString(R.string.loading), true); progress.setCanceledOnTouchOutside(false); } @Override public void onPageFinished(WebView view, String url) { progress.dismiss(); } } |
If you got an error “Activity has leaked window that was originally added”
>> Maybe You’re trying to show a Dialog after you’ve exited an Activity.
So simply call the dismiss() on the Dialog you created in before exiting your Activity, e.g. in onPause() or onDestroy()
1234567891011 @Overrideprotected void onDestroy() {super.onDestroy();progress.dismiss();}@Overrideprotected void onPause() {super.onPause();progress.dismiss();}
Source: developer.android.com/