1
我是android开发的新手。如何在等待HttpRespons时显示ProgressBar?
我开发了一个android web应用程序。当我点击子菜单或从该网页的链接时,使用RSS格式的RSS提要从网站获取相关文章。
该过程需要一些时间来加载页面。我想在内容正在加载时显示进度条。
我曾尝试下面的代码:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
dialog = ProgressDialog.show(this,"","Loading...");
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);//to remove title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//to remove notification bar
setContentView(R.layout.main);
wv = (WebView)findViewById(R.id.webview);
wv.getSettings().setJavaScriptEnabled(true);
wv.setBackgroundColor(0);
wv.setWebViewClient(new WebViewClient() {});
wv.loadUrl("file:///android_asset/HomePage.html");
}
@Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
// Save the state of the WebView
wv.saveState(outState);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// Restore the state of the WebView
wv.restoreState(savedInstanceState);
}
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);
dialog.show();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl("file:///android_asset/HomePage.html");
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
dialog.dismiss();
}
}
}
它显示进度条只在网页上,它也是后页面完全加载并没有解雇。
当从该网页中点击子菜单或链接时,应该如何显示进度条?提前致谢。
非常感谢你bove示例非常好,它解决了我的问题......但还有另外一个问题,其中一个内部页面包含java脚本,当它被重新写入该页面时。此进度条未显示。有什么方法可以在页面重新加载时调用以显示此进度条? – Ashutosh 2012-03-29 16:31:16
不知道..但是我使用页面加载脚本在我的HTML – 2012-03-30 07:41:26
当脚本执行时可见的剂量进度条? – Ashutosh 2012-03-30 15:43:13