无法在webview Android中显示内容html

时间:2016-04-05 06:22:21

标签: android html webview

我使用webview在数据库中显示内容html,但在显示时出错

我的代码

public void showData(){
    String title = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" /></head><body><h2 class=\"title\">" + article.getTitle()+ "</h2>\n";
    String timeAgo = "<div class=\"date_time_post\"><span class=\"date\">" + article.getYear() + "</span></div>";
    String content ="<div class=\"content\">" + article.getContent() + "</div></body></html>";

    String text = title + timeAgo + content;
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.loadDataWithBaseURL("file:///android_asset/", text, "text/html", "UTF-8", null);
}

this is the error result when display

我该如何解决?

1 个答案:

答案 0 :(得分:0)

这样做

webView.loadData(text, "text/html", null);

而不是

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