------ 用css定義樣式+WebView的其他設置
/**
* @param result 詳情H5
*/
private void setWebViewInfoContent(MissionInfoBeanOfNormal result) {
String missionInfoContent = result.getData().getContentList();
addSettingToWebView();
// String cssLayout = "<style>*{padding: 0;margin: 0}#webview_content_wrapper{margin: 0 15px 0 15px;}p{color: #333333;line-height: 2em;font-size: 28px;opacity: 1;}img {margin-top: 40px;margin-bottom: 40px;width: 100%;}</style>";
String cssLayout = "<style>*{padding: 0;margin: 0}#webview_content_wrapper{margin: 0 15px 0 15px;}p{color: #333333;line-height: 2em;opacity: 1;}img {margin-top: 40px;margin-bottom: 40px;width: 100%;}</style>";
String htmlModify = missionInfoContent.replaceAll("<br/>", "");
String htmlcontent = "<html>" + cssLayout + "<body><div id=\"webview_content_wrapper\">" + htmlModify + "</div></body></html>";
webView.loadDataWithBaseURL(null, htmlcontent, "text/html", "UTF-8", null);
}
/**
* 爲WebView添加設置
*/
private void addSettingToWebView() {
WebSettings settings = webView.getSettings();
//圖片大小自適應
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
settings.setDefaultFontSize((int) getResources().getDimension(R.dimen.y28));
}
---- 要展示的H5爲
<div class="image-package">
<img src="http://wwww.xxx.com/7bd7a038-8380-4d1c-9e86-72a897fd2eafTaskdetails3.png" data-by-webuploader="true"/>
</div><p>哈哈啊</p><p>哈哈1</p><p>哈哈2</p>
<div class="image-package"><img src="http://wwww.xxx.com/a7132c2b-8b8d-451a-a67b-4b642fd3e929Taskdetails2.png" data-by-webuploader="true"/>
</div><p><br/></p>