我试图用进度条为android制作一个webview应用程序,我尝试了很多这里的例子,但没有一个工作..我的问题是在一个框架页面或一个页面与Facebook喜欢或评论插件进展对话从来没有stoped ..这是我的代码..请测试它并告诉我有什么问题。
private WebView webview;
private ProgressDialog progressDialog;
boolean loadingFinished = true;
boolean redirect = false;
int nr = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webview = (WebView) findViewById(R.string.webview);
final Activity activity = this;
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;
webview.loadUrl(url);
return true;
}
public void onLoadResource(WebView view, String url) {
if (progressDialog == null) {
progressDialog = new ProgressDialog(activity);
progressDialog.setTitle("PitziWorld");
progressDialog.setMessage(progressDialog.toString());
progressDialog.setCancelable(isFinishing());
progressDialog.show();
}
loadingFinished = false;
}
public void onPageFinished(WebView view, String url) {
if(!redirect){
loadingFinished = true;
}
if(loadingFinished && !redirect){
if (progressDialog.isShowing() || progressDialog!=null) {
progressDialog.hide();
progressDialog = null;
}
} else{
redirect = false;
}
}
});
webview.loadUrl("http://www.pitziworld.ro");
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
WebView webView = (WebView) findViewById(R.string.webview);
//Verifica daca tasta apasata a fost back si daca exista istoric
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
// Daca nu a fost tasta back sau nu este istoric, returnam valoare buton
`
答案 0 :(得分:2)
public void onPageStarted(WebView view, String url, Bitmap favicon) {
mProgress.show();
}
在每个页面中加载进度条 这就是它!