I am using the web view for showing html pages, and I want to show a progress dialog until the page is loaded. When that is done, the dialog has to disappear. I have used AsyncTask for this, but the dialog doesn't show. See my code below:
class DownloadAysnc extends AsyncTask<String, String, Void>
{
ProgressDialog progressDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = ProgressDialog.show(OverView.this, "", "Please Wait ...");
}
@Override
protected Void doInBackground(String... arg0) {
webView.loadUrl("http://marico.com/html/investor/overview.php");
return null;
}
@Override
protected void onPostExecute(Void result){
super.onPostExecute(result);
progressDialog.dismiss();
}
}
And if I take the help of google docs to show the web page, then the HTML Tag is shown, but not the page. Below is that code:
String url = "http://google.co.in/";
String googleDocsUrl = "http://docs.google.com/viewer?url="+url;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");
startActivity(intent);
this.myWebView.loadUrl(googleDocsUrl);
Can someone help me with this?
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. In the above code, we have taken web view to show html content.
Overiding shouldOverrideUrlLoading inside WebViewClient implementation will open link in same window. webView. setWebChromeClient(new WebChromeClient() { @Override public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { WebView newWebView = new WebView(WebpageActivity.
This class was deprecated in API level 26. ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar , which can be embedded in your app's UI.
Use this code:
webView.setWebViewClient(new WebViewClient() {
ProgressDialog prDialog;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
prDialog = ProgressDialog.show(Activity.this, null, "loading, please wait...");
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
prDialog.dismiss();
super.onPageFinished(view, url);
}
});
webView.loadUrl(url);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With