-1

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.

1 Answers1

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