when open a web it will show how much will it load.
package com.mapking.cube;
private int mProgress = 0;
private static final int MAX_PROGRESS = 100;
private static final int DIALOG_PROGRESS = 4;
private String link = "http://www.baidu.com";
private ProgressDialog mProgressDialog;
private WebView webview;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
showDialog(DIALOG_PROGRESS);
mProgress = 0;
getWindow().requestFeature(Window.FEATURE_PROGRESS);
webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl(link);
webview.setWebViewClient(webViewClient);
webview.setWebChromeClient(webChromeClient);
setContentView(webview);
}
private WebViewClient webViewClient = new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
};
private WebChromeClient webChromeClient = new WebChromeClient(){
public void onProgressChanged(WebView view, int progress){
mProgress = progress;
mProgressDialog.setProgress(mProgress);
Log.e("xxxx", "progress: "+progress);
if (mProgress >= MAX_PROGRESS) {
mProgressDialog.dismiss();
}
}
};
@Override
protected Dialog onCreateDialog(int id){
switch (id){
case DIALOG_PROGRESS:
mProgressDialog = new ProgressDialog(CubeSideActivity.this);
mProgressDialog.setIcon(R.drawable.mapking);
mProgressDialog.setTitle("Connect to Server...");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setMax(MAX_PROGRESS);
return mProgressDialog;
}
return null;
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
webview.stopLoading();
super.onPause();
}