Android 与 js 简单互调

总结:

Android 调用 js:

在 Android 中创建通往 javascript 的接口;

在 html 中定义要执行的方法;

在 Android 中的具体事件中进行调用。

contentWebView.loadUrl("javascript:javacalljs()");



js中调用Android 方法 :

html中调用 Android 方法则反来,在 Andorid 中定义要调用的方法, html 中绑定事件进行调用。


Android 展示 html 页面

(1)project 视图下,在 Android 工程中新建目录 assets;

image

(2)在 assets 目录下新建 html 页面 如 show.html;

(3)Android 界面中在 WebView 中展示 show.html;

(4)Android 原生按钮点击执行 html 中的 js 方法;

image

界面设计:

image

html 中的 js:

image

效果:

image

js 调用 android 方法

还是需要一个接口:

image

Andorid中定义相应的执行方法(注意带上相应的注解):

image

html 中进行调用:

image

效果(弹的吐司没截下来):

image

更多相关文章

  1. android使用android:ellipsize="end"无效的解决方法
  2. Android(安卓)软件安装方法介绍
  3. Android单元测试初探Instrumentation
  4. Android实现全屏显示的方法
  5. Android实现全屏显示的方法
  6. android:versionCode和android:versionName 用途
  7. Unity与Android(安卓)Studio✨之间那些不清不楚的小秘密✨(Androi
  8. Unity3D 调用Android的提供的接口
  9. 【安全】Android(安卓)O 中的 Seccomp 过滤器

随机推荐

  1. Android(安卓)相对布局 RelativeLayout
  2. Android获得摄像头详细信息
  3. Android(安卓)访问权限清单
  4. Android夸进程通信机制六:使用ContentProv
  5. Android结构介绍
  6. android输入限制
  7. 什么是Android?
  8. android实现圆角矩形
  9. 专家专栏:Android层次化安全架构及核心组
  10. Android之系统自带的文字外观设置及实际