android混合开发中,标题栏需要客户端去实现,这是时就需要客户端实时监听网页中title的变化,并实时改变标题,同时还需要设置网页的加载进度,对进度进行监听,实现如下:
WebChromeClient vbClient = new WebChromeClient(){
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
//此处监听title变化,解决多次调转WebView title变化
center_txt.setText(title);
}
@Override
public void onProgressChanged(WebView view, int newProgress) { super.onProgressChanged(view, newProgress);
//此处监听进度条变化
if (seekBar != null) {
seekBar.setProgress(newProgress);
}
if (newProgress == 100) {
if (seekBar != null)
seekBar.setVisibility(View.GONE);
} }
};
webView.setWebChromeClient(vbClient);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
String title = view.getTitle();
if (!TextUtils.isEmpty(title)) {
center_txt.setText(title);
}
}
});