我有一个WebView
,我正在使用水平ProgressBar
。我已应用代码来显示其进度,但无法正常工作。这是代码。
mProgressBar = findViewById(R.id.pb);
mWebView.setWebViewClient(new WebViewClient() {
public void onProgressChanged(WebView view, int newProgress){
// Update the progress bar with page loading progress
int prog = mProgressBar.getProgress();
mProgressBar.setProgress(prog);
if(newProgress == 100){
// Hide the progressbar
mProgressBar.setVisibility(View.GONE);
}
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
// Visible the progressbar
mProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
finalMySwipeRefreshLayout1.setRefreshing(false);
mProgressBar.setVisibility(View.GONE);
}
});
我在上面的代码中使用了mProgressBar.setProgress(prog);
。那为什么它不起作用呢?请帮忙。
答案 0 :(得分:0)
您错误地设置了进度条,您应该使用webchromeClient
并将progressBar
设置为newProgress
,这里是如何做的:
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress){
// Update the progress bar with page loading progress
mProgressBar.setProgress(newProgress);
if(newProgress == 100){
// Hide the progressbar
mProgressBar.setVisibility(View.GONE);
}
}
}