图像在" html / text" Andrioid webview?没有任何HTML文件

时间:2016-11-04 06:07:46

标签: android webview assets

我想在未到达网站或离线时添加接收错误

所以这里工作正常....这里我想添加一个图像

但是Image没有显示表单资源文件夹

这是我的代码

@SuppressWarnings("deprecation")
public class Callback extends WebViewClient{
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){

        String html = "<div><p>&nbsp;<img style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"file:///android_asset/img/error.png\" alt=\"\" width=\"218\" height=\"218\" /></p></div><div><p style=\"color: black; font-size: 20px; text-align: left;\"><strong><span style=\"color: #808080;\">Oops, Unable to load information.</span></strong></p><div style=\"color: black; text-align: center;\"><span style=\"color: #ff99cc;\"><strong>Please check your Network connection.</strong></span></div><br /><div><p style=\"color: black; text-align: center;\"><strong>Or</strong><br /><br /></p><div style=\"color: black; text-align: center;\"><span style=\"color: #666699;\"><strong>Server May be Temporarily Down</strong></span></div><div style=\"color: black; text-align: center;\"><div style=\"color: black; text-align: center;\"><span style=\"color: #666699;\"><strong>Please Try After Sometime</strong></span></div></div></div></div>";

        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadData(html, "text/html", "UTF-8");

    }
}

1 个答案:

答案 0 :(得分:2)

检查此代码对我有用,

webView.loadDataWithBaseURL(null,html, "text/html", "UTF-8",null);