I use this code to load 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;
}
});
This code works but when the title is empty , the webview will show the url of the page in the title. How to solve it?
Do like this...
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("");
}
});
May it help !
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.