项目工程截图:
效果截图:
Code:
要想全面的了解这个还得要看一下这个网页的html代码,尤其是对javascript的处理的部分:
这是demo.html的代码:
从上面不难看出
这个的作用就是点击的时候,调用那个javascript函数wave。这个函数的注释部分:This is not called on the UI thread. Post a runnable to invokeloadUrl on the UI thread.
public voidaddJavascriptInterface(Objectobj,StringinterfaceName)
Use this function to bind an object to JavaScript so that the methods can be accessed from JavaScript.
IMPORTANT:
-
Using addJavascriptInterface() allows JavaScript to control your application. This can be a very useful feature or a dangerous security issue. When the HTML in the WebView is untrustworthy (for example, part or all of the HTML is provided by some person or
process), then an attacker could inject HTML that will execute your code and possibly any code of the attacker's choosing.
Do not use addJavascriptInterface() unless all of the HTML in this WebView was written by you.
-
The Java object that is bound runs in another thread and not in the thread that it was constructed in.
Parameters
obj
The class instance to bind to JavaScript, null instances are ignored. |
interfaceName
The name to used to expose the instance in JavaScript. |
boolean android.os..post( r)
Causes the Runnable r to be added to the message queue. The runnable will be run on the thread to which this handler is attached.(在这个程序里面也就是说会在主线程)
Parameters:
r The Runnable that will be executed.
Returns:
Returns true if the Runnable was successfully placed in to the message queue. Returns false on failure, usually because the looper processing the message queue is exiting.
public voidsetWebChromeClient(WebChromeClientclient)
Set the chrome handler. This is an implementation of WebChromeClient for use in handling JavaScript dialogs, favicons, titles, and the progress. This will replace the current handler.
Parameters
client
An implementation of WebChromeClient. |
分享到:
相关推荐
android webview学习记录 android webview学习记录
android webview 学习资料
androidWebView学习.pdf
最近半年在做android开发,借鉴大牛和自己总结的一些经验,分享出来
本篇内容主要给大家讲解了Android Webview拦截ajax请求的详细讲解,需要的朋友一起来学习一下。
android 8.0 webview 拍照、预览、二维码扫描比较完整的例子,对于权限检查控制,有比较完善的提示写法。可以下载后,直接在android studid上运行,编译版本和target版本均是SDK android 8.0,最低版本设置成了...
android webview开发应用,用户可看到源码是个不错的学习资料
Android-X5WebView基本封装和使用 通过OkHttp拦截器、自定义CookieJar有效完成客户端与H5端的Cookie同步管理 监听WebView的加载进度 滚动条的设置(隐藏或者显示,内侧显示还是外侧显示) 优化X5WebView的预加载问题...
android webview 控件学习及例子
Android WebView打开网址浏览网页,实现浏览器打开网页的功能,需要为WebView设置WebChromeClient,要实现这个功能,需要几个步骤:用户输入网址,将焦点移到EditText供输入,然后判断用户输入的是否是网址,是网址...
本软件主要是基于Android的WebViewJS的一些应用,输入某个网址的时候,当点击某个应用的时候就会得到相应的值。大家可以看看其代码。学习学习其对应的应用,希望对大家有所帮助。
使用webview做的一个简单浏览器 供学习参考 可以运行于android2.3之上
webview学习记录.rar android webview学习笔记 很高参考价值
最近写项目,有个功能是webView中的网页返回到上个页面,我在网上找了一下,总结了一下,把demo上传到这,和大家分享学习
android webview 加载本地html.zip,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
Android APP使用WebView调用H5页面完成摄像头扫描二维码软件源码,可供学习及设计参考。
最近写项目,用到了webView,这是一个很重要的控件,但是在开发中要拿到网址,所以我写了一个例子上传和大家交流学习
自己学习android webview的新的体验,供大家参考
html5越来越火了,web页面在app的嵌入的也越来越多了android5.0对WebView又做了加强,可以看到Web开发在android开发中的地位越来越高了,现在就开始学习一下android中的WebView。