webview加载本地html 返回怎么处理
2个回答
展开全部
package com.aloong.map;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebSettings;
import android.webkit.WebView;
9public class MyMap extends Activity {
private static String TAG = MyMap.class.getName();
private WebView mWebView;
private Handler mHandler;
private WebSettings mWebSettings;
/** *//** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) this.findViewById(R.id.webview);
mHandler = new Handler();
// 设置支持JavaScript等
mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
mWebSettings.setBuiltInZoomControls(true);
mWebSettings.setLightTouchEnabled(true);
mWebSettings.setSupportZoom(true);
mWebView.setHapticFeedbackEnabled(false);
// mWebView.setInitialScale(0); // 改变这个值可以设定初始大小
//重要,用于与页面交互!
mWebView.addJavascriptInterface(new Object() {
@SuppressWarnings("unused")
public void oneClick(final String locX, final String locY) {//此处的参数可传入作为js参数
mHandler.post(new Runnable() {
public void run() {
mWebView.loadUrl("javascript:shows(" + locX + "," + locY + ")");
}
});
}
}, "demo");//此名称在页面中被调用,方法如下:
//<body onClick="window.demo.clickOnAndroid(event.pageX,event.pageY)">
final String mimeType = "text/html";
final String encoding = "utf-8";
final String html = "";// TODO 从本地读取HTML文件
mWebView.loadDataWithBaseURL("file:///sdcard/", html, mimeType,
encoding, "");
}
}
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.webkit.WebSettings;
import android.webkit.WebView;
9public class MyMap extends Activity {
private static String TAG = MyMap.class.getName();
private WebView mWebView;
private Handler mHandler;
private WebSettings mWebSettings;
/** *//** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) this.findViewById(R.id.webview);
mHandler = new Handler();
// 设置支持JavaScript等
mWebSettings = mWebView.getSettings();
mWebSettings.setJavaScriptEnabled(true);
mWebSettings.setBuiltInZoomControls(true);
mWebSettings.setLightTouchEnabled(true);
mWebSettings.setSupportZoom(true);
mWebView.setHapticFeedbackEnabled(false);
// mWebView.setInitialScale(0); // 改变这个值可以设定初始大小
//重要,用于与页面交互!
mWebView.addJavascriptInterface(new Object() {
@SuppressWarnings("unused")
public void oneClick(final String locX, final String locY) {//此处的参数可传入作为js参数
mHandler.post(new Runnable() {
public void run() {
mWebView.loadUrl("javascript:shows(" + locX + "," + locY + ")");
}
});
}
}, "demo");//此名称在页面中被调用,方法如下:
//<body onClick="window.demo.clickOnAndroid(event.pageX,event.pageY)">
final String mimeType = "text/html";
final String encoding = "utf-8";
final String html = "";// TODO 从本地读取HTML文件
mWebView.loadDataWithBaseURL("file:///sdcard/", html, mimeType,
encoding, "");
}
}
展开全部
[html] view plain
<!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>Insert title here</title>
<script type="text/javascript">
function show(jsondata){
var jsonobjs = eval(jsondata);
var table = document.getElementById("personTable");
for(var y=0; y<jsonobjs.length; y++){
var tr = table.insertRow(table.rows.length);
var td1 = tr.insertCell(0);
var td2 = tr.insertCell(1);
td2.align = "center";
var td3 = tr.insertCell(2);
td3.align = "center";
td1.innerHTML = jsonobjs[y].name;
td2.innerHTML = jsonobjs[y].amount;
td3.innerHTML = "<a href='javascript:contact.call(\""+ jsonobjs[y].phone+ "\")'>"+ jsonobjs[y].phone+ "</a>";
}
}
</script>
</head>
<body onload="javascript:contact.showcontacts()">
<button id="button" onclick = "javascript:contact.toast('123')">haha</button>
<table border="0" width="100%" id="personTable" cellspacing="0">
<tr>
<td width="30%">姓名</td>
<td width="30%" align="center">存款</td>
<td align="center">电话</td>
</tr>
</table>
</body>
</html>
<!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>Insert title here</title>
<script type="text/javascript">
function show(jsondata){
var jsonobjs = eval(jsondata);
var table = document.getElementById("personTable");
for(var y=0; y<jsonobjs.length; y++){
var tr = table.insertRow(table.rows.length);
var td1 = tr.insertCell(0);
var td2 = tr.insertCell(1);
td2.align = "center";
var td3 = tr.insertCell(2);
td3.align = "center";
td1.innerHTML = jsonobjs[y].name;
td2.innerHTML = jsonobjs[y].amount;
td3.innerHTML = "<a href='javascript:contact.call(\""+ jsonobjs[y].phone+ "\")'>"+ jsonobjs[y].phone+ "</a>";
}
}
</script>
</head>
<body onload="javascript:contact.showcontacts()">
<button id="button" onclick = "javascript:contact.toast('123')">haha</button>
<table border="0" width="100%" id="personTable" cellspacing="0">
<tr>
<td width="30%">姓名</td>
<td width="30%" align="center">存款</td>
<td align="center">电话</td>
</tr>
</table>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询