——各类控件的使用(控件)-网页浏览器 【若对该知识点有更多想了解的,欢迎私信博主~~】
在main文件夹下创建Assets文件夹,将html文件导入到文件夹中
webView.loadUrl("file:///android_asset/index.html");在Android中编写JS接口
class AndroidAndJSInterface{ @JavascriptInterface public String showToast(){ String word="Hello World"; return word; } }为WebView添加Javascript接口
webView.addJavascriptInterface(new AndroidAndJSInterface(),"Android");在HTML中使用接口
<!doctype html> <head> <title>Demo</title> <script> function val(){ var word=window.Android.showToast(); document.getElementById("btn").value=word; } </script> </head> <body> <input type="button" value="内容" id="btn" name="btn" onclick="val()"/> </body> </html>