混合开发-webview和原生交互

本文介绍了移动开发中的混合开发,特别是通过WebView实现网页与原生Android应用的交互。通过创建一个包含WebView的Activity,并设置JavaScriptInterface,实现了从原生应用调用网页接口的功能。文中提供了一个简单的DEMO,并列举了常用的混合开发框架,如Weex、Ionic和Wex5。
摘要由CSDN通过智能技术生成

混合开发在移动开发中很常见,比如qq中的运动,厘米秀等功能都是用网页实现的。
混合开发中一个重要的功能就是网页和原生接口的数据交互,下面将实现一个小demo.

新建一个activity,布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.h.learn.WebViewActivity">

    <WebView
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/my_web_view"
        />

    <LinearLayout
        android:background="@drawable/webview_bg"
        android:layout_weight="1"
        android:orientation="vertical"
        android:layout_width
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值