通过设置WebChromeClient来实现进度条的显示和隐藏。
示例代码:
//初始化webview
WebView webView=new WebView(this);
//设置WebChromeClient
webView.setWebChromeClient(new WebChromeClient(){
public void onProgressChanged(WebView view, int newProgress) {
//设置进度条的显示
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(newProgress);
if (newProgress==100) {
//设置进度条的隐藏
progressBar.setVisibility(View.GONE);
}
}
});