Android中调用js方法及js中调用本地方法,有需要的朋友可以参考下。
Android中内置了WebKit模块,而该模块的Java层视图类就是WebView,所有需要使用Web浏览器功能的Android都需要创建该视图类对象显示和处理请求的网络资源。目前WebKit支持Http、Https、Ftp和JavaScript请求。下面我们重点看一下如何在Android中调用JavaScript方法以及如何在js中调用本地方法。
1、在Assets下放一个简单的html文件jstest.html
function showMsg(){
alert("hello world!");
}
function showMsgInAndroid(){
myjs.showMsg('hello in android!');
}
测试js使用
调用android方法
2、布局文件main.xml
android:id="@+id/rl_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
android:id="@+id/wv_test"
android:layout_width="fill_parent"
android:layout_he