我使用此代码加载WebView
web.setWebChromeClient(new WebChromeClient(){
@Override
public void onReceivedTitle(WebView view, String title) {
getWindow().setTitle(title); //Set Activity tile to page title.
}
});
web.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
此代码有效,但当标题为空时,webview将显示标题中页面的网址。怎么解决?
答案 0 :(得分:0)
这样做......
web.setWebChromeClient(new WebChromeClient(){
@Override
public void onReceivedTitle(WebView view, String title) {
if(title!=null && title!="")
getWindow().setTitle(title); //Set Activity tile to page title.
else
getWindow().setTitle("");
}
});
愿它有所帮助!