WebView--展示H5(二)

------ 用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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值