Android WebView 获取网页的标题
final TextView txtTitle = (TextView) findViewById(R.id.txtTitle);
final WebView webView = (WebView)findViewById(R.id.btnWebView);
WebChromeClient wvcc = new WebChromeClient() {
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
txtTitle.setText("ReceivedTitle:" +title);
}
};
// 设置setWebChromeClient对象
webView.setWebChromeClient(wvcc);
// 创建WebViewClient对象
WebViewClient wvc = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//使用自己的WebView组件来响应Url加载事件,而不是使用默认浏览器器加载页面
webView.loadUrl(url);
//消耗掉这个事件。Android中返回True的即到此为止吧,事件就会不会冒泡传递了,我们称之为消耗掉
return true;
}
};
webView.setWebViewClient(wvc);
}