public class MainActivity extends AppCompatActivity {
private WebView mWebView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showWebView();
}
private void showWebView() {
mWebView = (WebView) findViewById(R.id.mWebView);
WebSettings webSettings = mWebView.getSettings();
// 設(shè)置android下容許執(zhí)行js的腳本
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("file:///android_asset/hello.html");
// 這里加載數(shù)據(jù)不會(huì)顯示,因?yàn)閔ello.html還沒加載完成字逗,所以沒有顯示
// String content = "{\"content\":\"\\u003cdiv\\u003e\\u003cp\\u003e由日本廠商N(yùn)EXON推出的戰(zhàn)略RPG手游新作《奇想之戰(zhàn)》于7月28日在iOS/Android平臺(tái)正式上線肩民!\\u0026nbsp;\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697849067464_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"2\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e本作是一款融合了地形喻犁、相性等戰(zhàn)略要素的“進(jìn)化型”戰(zhàn)略RPG游戲,講述作為天才魔法使的主人公和他的同伴們拯救世界的冒險(xiǎn)故事屡萤。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057507557_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"3\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057538582_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057587465_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"5\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057613407_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"6\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e為紀(jì)念游戲正式上線,游戲開服后2周內(nèi)登錄游戲的全體玩家都將獲得限定道具。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697850097742_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e官網(wǎng)地址:\\u003ca href\\u003d\\\"http://mobile.nexon.co.jp/fwt\\\"\\u003ehttp://mobile.nexon.co.jp/fwt\\u003c/a\\u003e\\u003c/p\\u003e\\u003cp\\u003e\\u003cbr/\\u003e\\u003c/p\\u003e\\u003c/div\\u003e\",\"title\":\"戰(zhàn)略RPG手游新作《奇想之戰(zhàn)》正式上線\"}\n";
// mWebView.loadUrl("javascript: showHtmlcallJava2(" + content + ")");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
//這里加載數(shù)據(jù)是有效的漾脂,hello.html已經(jīng)加載完成了。
String content = "{\"content\":\"\\u003cdiv\\u003e\\u003cp\\u003e由日本廠商N(yùn)EXON推出的戰(zhàn)略RPG手游新作《奇想之戰(zhàn)》于7月28日在iOS/Android平臺(tái)正式上線胚鸯!\\u0026nbsp;\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697849067464_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"2\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e本作是一款融合了地形骨稿、相性等戰(zhàn)略要素的“進(jìn)化型”戰(zhàn)略RPG游戲,講述作為天才魔法使的主人公和他的同伴們拯救世界的冒險(xiǎn)故事姜钳。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057507557_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"3\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057538582_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057587465_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"5\\\"/\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201606/14665057613407_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"6\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e為紀(jì)念游戲正式上線坦冠,游戲開服后2周內(nèi)登錄游戲的全體玩家都將獲得限定道具。\\u003c/p\\u003e\\u003cp\\u003e\\u003cimg src\\u003d\\\"http://qn.18touch.com/uploads/acg201607/14697850097742_water.jpg\\\" width\\u003d\\\"600\\\" alt\\u003d\\\"4\\\"/\\u003e\\u003c/p\\u003e\\u003cp\\u003e官網(wǎng)地址:\\u003ca href\\u003d\\\"http://mobile.nexon.co.jp/fwt\\\"\\u003ehttp://mobile.nexon.co.jp/fwt\\u003c/a\\u003e\\u003c/p\\u003e\\u003cp\\u003e\\u003cbr/\\u003e\\u003c/p\\u003e\\u003c/div\\u003e\",\"title\":\"戰(zhàn)略RPG手游新作《奇想之戰(zhàn)》正式上線\"}\n";
mWebView.loadUrl("javascript: showHtmlcallJava2(" + content + ")");
}
});
}
}
其中的hello.html如下:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-store,no-cache">
<meta name="Handheldfriendly" content="true">
<meta name="viewport" content="width=100%; initial-scale=1.0; user-scalable=yes">
<meta name="robots" content="all">
<meta name="keywords" contect="doodle, mobile, doodlemobile, game, games">
<meta name="description" content="Make People's Mobile Life More Connected Through Games.">
<meta charset="UTF-8">
<meta content="initial-scale=1,maximum-scale=1,user-scalable=no,width=device-width"
name="viewport">
<link rel="stylesheet" type="text/css" href="css/css.css">
<script src="js/jquery.min.js"></script>
<title>jsandroid_test</title>
<script type="text/javascript" language="javascript">
//此方法是調(diào)用了android的方法HtmlcallJava2()
function showHtmlcallJava2(json){
$(".news-content-block .title h1").html(json.title);
$(".news-content-block .news-content").html(json.content.replace(/_ueditor_page_break_tag_/g,""));
//調(diào)用android中的方法
window.jsObj.HtmlcallJava2(str+","+str1);
}
</script>
</head>
<body>
<section>
<article class="news-content-block">
<div class="news-content-block-hd">
<div class="title">
<!-- 文章標(biāo)題-->
<h1></h1>
</div>
</div>
<div class="news-content-block-bd">
<!--文章內(nèi)容-->
<div class="news-content"></div>
</div>
</article>
</section>
</body>
</html>