如何在android中为Web浏览器创建加载对话框? 应用程序应加载URL并显示加载对话框。当web浏览器加载url时,关闭加载对话框。
答案 0 :(得分:1)
首先创建WebView
并使其扩展自定义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");
您的自定义WebViewClient
会在页面开始加载和页面加载完成时通知您。只需在页面加载时显示ProgressBar
,并在完成加载时隐藏。
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);
}
}