Android webView始终显示倾斜的网址

时间:2016-06-23 11:05:38

标签: android android-webview

我使用此代码加载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将显示标题中页面的网址。怎么解决?

1 个答案:

答案 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("");
        }
    });

愿它有所帮助!