android native+web app架构

1.核心技术和例子

http://developer.android.com/resources/articles/using-webviews.html

Using WebViews

它介绍了 javascript <->java,之间的相互调用方法,简单但是所有类似架构的基础。

a:javascript调用java

First, JavaScript running inside the WebView can call out to code in your Activity. You can use this to have your JavaScript trigger actions like starting a new activity, or it can be used to fetch data from a database orContentProvider. The API for this is very simple: just call theaddJavascriptInterface() method on your WebView. You pass an object whose methods you want to expose to JavaScript and the name to use when making calls. You can see the exact syntax in WebViewDemo. java. Here we are making our DemoJavascriptInterface object available to JavaScript where it will be called "window.demo".


b: java 调用 javascript

Second, your Activity can invoke JavaScript methods. All you have to do is call theloadUrl method with the appropriate JavaScript call:

mWebView.loadUrl("javascript:wave()");


2.非常详细的一个webview的例子WebView Demo!!!

http://eagle.phys.utk.edu/guidry/android/webviewdemo.html

3.androidwebview中javascript执行alert无效?





3.androidwebview中javascript执行alert无效?


需要使用WebChromeClient

webview.setWebChromeClient(new WebChromeClient());

甚至还能覆盖alert的实现:


  str--要显示在消息对话框中的文本webview.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
           //Required functionality here
           return super.onJsAlert(view, url, message, result);
    }
});

相关参考:JavaScript alert()函数详细使用说明
http://www.php100.com/html/webkaifa/javascript/2010/1009/6482.html

alert--弹出消息对话框,并且alert消息对话框通常用于一些对用户的提示信息。

  JavaScript alert()函数

  alert--弹出消息对话框(对话框中有一个OK按钮)

  alert,中文"提醒"的意思

  alert函数语法

  alert(str);

  alert函数说明

  alert消息对话框通常用于一些对用户的提示信息,例如在表单中输入了错误的数据时。

  提示:消息对话框是由系统提供的,因此样式字体在不同浏览器中可能不同。

  提示:消息对话框是排它的,也就是在用户点击对话框的按钮前,不能进行任何其它操作。

  提示:消息对话框通常可以用于调试程序。

  示例

alert("Hellodreamdu!");

 
  1. alert('Welcometo<br/>dreamdu!');
  2. alert('Welcometo\ndreamdu!');

  注意上面的第二个与第三个例子,只有第三个例子才能实现换行,参考ASCII码表,使用HTML中的br标签无法换行。

2. 非常好的HTML 和HTML DOM学习资料

http://www.w3school.com.cn/htmldom/dom_obj_window.asp

http://www.w3school.com.cn/tags/tag_comment.asp

http://www.htmlcodetutorial.com/search.html?cx=partner-pub-6155056320102818%3Aomfj3qxh2mm&cof=FORID%3A10&ie=ISO-8859-1&q=a&sa=Site+Search


html中a标签中的onclick和href的使用

http://www.cnblogs.com/caishuhua226/archive/2012/03/20/2408165.html



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值