webView = (WebView) findViewById(R.id.article_webview);

//WebView启用Javascript脚本运行
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

//运行映射,将本Activity映射到js2java对象上面
webView.addJavascriptInterface(this, "js2java");
如果在当前Activity中有例如以下方法
public void webViewImageClick(){
Intent intent = new Intent(context, PhotoScaleActivity.class);
startActivity(intent);
}
记住这里,必须为public方法,才干生效。 这样。我们在图片上加入点击事件如 window.js2java.webViewImageClick(); 就可以启用 webViewImageClick 函数

相关文章:

  • 2021-06-08
  • 2021-05-23
  • 2021-05-18
  • 2022-12-23
  • 2021-03-31
  • 2021-05-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案