添加addJavascriptInterface
val ws: WebSettings = wv.getSettings()
ws.javaScriptEnabled = true
wv.addJavascriptInterface(object : Any() {
@JavascriptInterface
fun performClick(strl: String) {
Toast.makeText(this@YourActivity, stringVariable, Toast.LENGTH_SHORT).show()
}
}, "ok")
在onclick中添加对应方法,这里的"ok"是addJavascriptInterface的name参数
<button type="button" onclick="ok.performClick();">OK</button>
评论 (0)