• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

android javascript:android与javascri_js

javascript 搞代码 7年前 (2018-06-13) 169次浏览 已收录 0个评论

               下面这一节来介绍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&quot;
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"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here http://www.cxybl.com</title&gt;
<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 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:android javascript:android与javascri_js
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址