亲测可用
WebSettings settings =webview.getSettings();
settings.setJavaScriptCanOpenWindowsAutomatically(true);
settings.setUseWideViewPort(true);//将图片调整到适合webView的大小
settings.setLoadWithOverviewMode(true);//缩放至屏幕大小
settings.setBlockNetworkImage(false);//解决图片加载不出来的问题
settings.setAllowFileAccessFromFileURLs(true);//是否允许跨域
settings.setAllowUniversalAccessFromFileURLs(true);
1.加载富文本方法
webview.loadDataWithBaseURL(null, getHtmlData(“此处为要加载的富文本内容”), "text/html", "utf-8", null);
2.此处为js方法
private StringgetHtmlData(String bodyHTML) {
String head ="<head>" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> " +
"<style>img{max-width: 100%; width:auto; height:auto!important;}</style>" +
"</head>";
return "<html>" + head +"<body>" + bodyHTML +"</body></html>";
}
网友评论