我有一个 WebView,它可以很好地加载一个 URL。我得到了一个 WebViewClient 并扩展了 onProgressChanged,但据我所知,它没有被调用。有任何想法吗?
wv.setWebViewClient(new WebViewClient(){
public void onProgressChanged(final WebView view, final int newProgress) {
Log.e("APPNAME", String.valueOf(newProgress));
if (newProgress < 100 && progressBar.getVisibility() == ProgressBar.GONE){
progressBar.setVisibility(ProgressBar.VISIBLE);
}
progressBar.setProgress(newProgress);
progressTxt.setText(newProgress);
if (newProgress == 100){
progressBar.setVisibility(ProgressBar.GONE);
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
InputStream is = null;
byte[] buffer = null;
try {
is = getAssets().open("error.html");
int size = 0;
size = is.available();
buffer = new byte[size];
is.read(buffer);
is.close();
}
catch(Exception e){
}
String str = new String(buffer);
str = str.replace("%@", description);
view.loadDataWithBaseURL("file:///android_asset/", str, "text/html", "utf-8", null);
}
});