有话要说:
本篇主要总结了简单的Android与js互相调用的方法。
在开发过程中遇到了需要在安卓中调用js方法的需求,于是将具体的实现过程总结成这篇博客。
效果:
其中“调用安卓方法”按钮是html中的按钮;“调用JS方法”按钮是app中的按钮。

本地HTML:
首先,在app根目录新建一个assets文件夹,并在文件夹内新建一个本地html文件,如下图

接着编写一个简单的html文件:
1 <html lang="zh-CN"> 2 <p id='p'>hello world</p> 3 4 <script> 5 function test(){ 6 document.getElementById("p").innerHTML += " 你好!" 7 } 8 </script> 9 10 <button onclick="justTest.hello('js调用安卓方法!')">调用安卓方法</button>11 12 </html>
Android布局文件:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent"

