how can I make loading dialog for web browser in android? application should load url and show loading dialog. and when web browser load url compeletly close the loading dialog.
Asked
Active
Viewed 71 times
-1
-
2Have you tried anything so far? – Prokash Sarkar Aug 07 '15 at 08:43
-
1possible duplicate of [android webview client activity indicator](http://stackoverflow.com/questions/9310784/android-webview-client-activity-indicator) – Jibran Khan Aug 07 '15 at 08:46
-
possible duplicate of [Android showing progress bar for webview in android](http://stackoverflow.com/questions/23309227/android-showing-progress-bar-for-webview-in-android) – King of Masses Aug 07 '15 at 08:59
1 Answers
1
First create a WebView
and make it extends a custom WebViewClient
web = (WebView) findViewById(R.id.webview01);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
web.setWebViewClient(new myWebClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl("http://www.example.com");
Your custom WebViewClient
will let you know when the page has started loading and when the page has finished loading. Simply show the ProgressBar
while the page is loading and hide upon its finished loading.
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
progressBar.setVisibility(View.VISIBLE);
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
}

Prokash Sarkar
- 11,723
- 1
- 37
- 50