我想使用WebView来显示我的脚本:
webView.loadData(script, "text/html; charset=UTF-8", null);
该脚本由JSON发送,因为发送html:
<html>
<head>
<style>
html, body{
margin: 0;
padding:0;
height: 100%;
box-sizing: border-box;
}
.bf_container{
width:100%;
height: 100%;
}
.bf_item{
box-sizing: border-box;
width: 33%;
float:left;
padding: 5px 10px;
}
.bf_item img{
max-width: 100%;
}
</style>
</head>
<body>
<div class="bf_container">
<div class="bf_item">
<a href="#">
<h3>Title</h3>
<img src="http://placehold.it/350x150" onClick="Android.onAdClicked('app_url')">
</a>
</div>
<div class="bf_item">
<a href="#">
<h3>Title</h3>
<img src="http://placehold.it/350x150">
</a>
</div>
<div class="bf_item">
<a href="#">
<h3>Title</h3>
<img src="http://placehold.it/350x150">
</a>
</div>
<div class="bf_item">
<a href="#">
<h3>Title</h3>
<img src="http://placehold.it/350x150">
</a>
</div>
<div class="bf_item">
<a href="#">
<h3>Title</h3>
<img src="http://placehold.it/350x150">
</a>
</div>
<div class="bf_item">
<a href="#">
<h3>Title</h3>
<img src="http://placehold.it/350x150">
</a>
</div>
</div>
</body>
</html>
必须编码为:
<html> <head> <style> html, body{ margin: 0; padding:0; height: 100%; box-sizing: border-box; } .bf_container{ width:100%; height: 100%; } .bf_item{ box-sizing: border-box; width: 33%; float:left; padding: 5px 10px; } .bf_item img{ max-width: 100%; } </style> </head> <body> <div class="bf_container"> <div class="bf_item"> <a href="#"> <h3>Title</h3> <img src="http://placehold.it/350x150" onClick="Android.onAdClicked('app_url')"> </a> </div> <div class="bf_item"> <a href="#"> <h3>Title</h3> <img src="http://placehold.it/350x150"> </a> </div> <div class="bf_item"> <a href="#"> <h3>Title</h3> <img src="http://placehold.it/350x150"> </a> </div> <div class="bf_item"> <a href="#"> <h3>Title</h3> <img src="http://placehold.it/350x150"> </a> </div> <div class="bf_item"> <a href="#"> <h3>Title</h3> <img src="http://placehold.it/350x150"> </a> </div> <div class="bf_item"> <a href="#"> <h3>Title</h3> <img src="http://placehold.it/350x150"> </a> </div> </div> </body> </html>
在WebView中正确显示此类HTML的方法是什么?因为到目前为止它不处理脚本,只显示脚本文本。