下面这一节来介绍android和JavaScript是怎么相互调用的,这样我们的UI界面设计起来就简单多了,而且UI设计起来也可以跨平台。现在有好多web app前台框架了,比如sencha和jquery mobile等。相信未来随着web app的发展我们同样可以使用html设计出和本地应用一样漂亮的界面。这些虽然很美好,但是现在还有很多弊端,比如比本地框架调用慢的多,因为手机是受限的设备,所以处理起来和反应都是比较慢的,期望未来会有较大的发展。哈哈!
废话不多说,下面来写一个WebViewDemo实现android与javascript相互调用。
先看一下main.xml用了哪些控件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="调用javascript"
/>
</LinearLayout>
然后给出我们的demo.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 http://www.cxybl.com</title>
<script type="text/javascript">
function show(content){
document.getElementById("countent").innerHTML=
"这是我的javascript调用. 这是:"+content;
}
</script>
</head>
<body>
<table align="center">
<tr><td>姓名</td><td>电话</td></tr>
<tr><td>小明</td><td><a href="javascript:demo.startPhone(123)">123</a></td></tr>
<tr><td>小王</td><td><a href="javascript:demo.startPhone(456)">456</a></td></tr>
</table>
<p id="countent">html原始数据</p> 本文链接http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20130110/35823.html
欢迎大家阅读《android javascript:android与javascri…_js》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码