public String getNewContent(String htmltext) { org.jsoup.nodes.Document doc; try { doc = Jsoup.parse(htmltext); Elements elements = doc.getElementsByTag("img"); for (Element element : elements) { element.attr("style", "width:100%;height:auto;"); } return doc.toString(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; }
webView.loadDataWithBaseURL("", getNewContent(entity.getUpgradeDescription()), "text/html", "UTF-8", "");
或是(未经过测试)
webView.getSettings().setJavaScriptEnabled(true);
special_content = special_content.replaceAll("&", "");
special_content = special_content.replaceAll(""", "\"");
special_content = special_content.replaceAll("<", "<");
special_content = special_content.replaceAll(">", ">");
special_content = special_content.replaceAll("\\n", "<br>");//换行
special_content = special_content.replaceAll("<img", "<img width=\"100%\"");//图片不超出屏幕
webView.loadDataWithBaseURL(null, special_content, "text/html", "utf-8", null);