StringBuffer sb = new StringBuffer(); // sb.append(this.mContext.getString(R.string.html_coupon_begin)); sb.append(this.mContext.getString(R.string.ios_html_coupon_begin)); sb.append(mHtmlContent); // sb.append(this.mContext.getString(R.string.html_template_end)); sb.append(this.mContext.getString(R.string.ios_html_end)); // 测试用,by caisenchuan // KLog.d(TAG, "setMainView : " + sb.toString()); // FileUtil.createNewFile(FileUtil.DIR_CACHE, "test.html", // sb.toString().getBytes()); // 因为中英文切换的时候,可能会影响WebView内容的高度,所以此处进行重设 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); mWebView.setLayoutParams(params); mWebView.loadDataWithBaseURL(null, sb.toString(), "text/html", "utf-8", null);
<string name="html_begin"> <![CDATA[ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8" /> <title>Dealmoon</title> <meta http-equiv="Content-Language" content="en-us" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="description" content="Description" /> <meta name="keywords" content="Keywords" /> <meta name="viewport" content="width=device-width; minimum-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> <style> body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td { padding:0; margin:0; } h1, h2, h3, h4, h5, em { font-style: normal; font-weight: normal; } a { color:#436DA9; text-decoration:none; } body, #container, #container span, #container a, #container ul li, #container ul li a, #container ul li span { font-size:%@px!important; line-height:1.5!important; font-family:arial,sans-serif!important; } #container { padding:10px; } #container img { max-width: 100%%!important; height: auto!important; } #container ul { display:block; } #container li { margin:3px 0px 0px 20px; background: -webkit-image-set( url(web_dot.png) 1x, url(web_dot@2x.png) 2x, url(web_dot@3x.png) 3x) 0px 12px no-repeat; } #container ul li ul{ padding:0; } .coupon .coupon_code { border:1px solid #bababa!important; background:#f6f6f6!important; color:#5c5c5c!important; border-radius:2px!important; padding:0 5px!important; } </style> </head> <body οncοntextmenu=\'return false\' οndragstart=\'return false\' onselectstart =\'return false\' οnselect=\'document.selection.empty()\' οncοpy=\'document.selection.empty()\' onbeforecopy=\'return false\' οnmοuseup=\'document.selection.empty()\'>//防止webview复制粘贴 <div id="container"> ]]> </string> <string name="html_end"> <![CDATA[ </div> </body> </html> ]]> </string>