今天给大家写了一个简单的小dome android与js交互(一)我在这里说明一下 不是我的原创 我也是从网上找的 给大家演练一下,好了进入正题吧
首先我给大家看的是我从网上随便复制的一串html文件 首先这个文件是要放到你项目中main的文件夹中assets文件里(没有的话自己创建一个assets文件夹 切记:一定是要放到main文件下的assets文件夹中)
<html> <head> <meta charset="utf-8"> <title>Carson_Ho</title> <!--// JS代码--> <script> <!--// Android需要调用的方法--> function callJS(){ alert("Android调用了JS的callJS方法"); } </script> </head> </html>
接下来我们就要写个布局了当咱们一听Android与H5交互立刻想到了Android中的控件WebView 接下来看一下我写的布局界面比较丑陋 只不过是方便测试
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.bwp.jsjiaohu.MainActivity" android:background="#ffffff" > <LinearLayout android:layout_width="match_parent" android:layout_height=&#