Android HTML与原生交互

前言

HTML+原生交互是最近比较流行的方式,很多人都在使用,用了这么久的这种模式,小编#整合了下,方便技术更替之后再次查看,也希望这篇文章能够对你有用。
下面就简单整合下,HTML与原生如何交互
1.布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/comm_bg"
    android:orientation="vertical">

    <include
        android:id="@+id/layout_top_bar"
        layout="@layout/top_bar" />
   //PtrClassicFrameLayout  [下拉刷新框架view]
    <com.reach.doooly.pullresh.PtrClassicFrameLayout
    xmlns:cube_ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/view_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/layout_top_bar">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">
                <WebView
                    android:id="@+id/view_webview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
                <ProgressBar
                    android:id="@+id/view_progressbar"
                    style="?android:attr/progressBarStyleHorizontal"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:progressDrawable="@drawable/pull_progressbar_pg"
                    android:visibility="gone" />
            </RelativeLayout>
            <include layout="@layout/webview_err_view"
                android:visibility="gone"/>
        </RelativeLayout>
    </com.reach.doooly.pullresh.PtrClassicFrameLayout>
</RelativeLayout>

2.activity
package com.reach.doooly.server;

import android.app.Activity;
import android.os.Bundle;

import com.reach.doooly.R;

/**
 * Created by Albert on 2017/10/16.
 */
public class WebViewActivity extends Activity{
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview_layout);
    }
}

下面我们需要做的是
[1]初始化webview

 private WebView webView;
 private void initView(){
        webView=(WebView)findViewById(R.id.view_webview);
    }

[2]webview提供javascript支持

        WebSettings webSettings = webView.getSettings();
        webSettings.setTextZoom(100);//设置web端界面不随html改变
        webSettings.setDomStorageEnabled(true); // 使用localStorage
        webSettings.setLoadWithOverviewMode(true); // 设置页面自适应屏幕
        webSettings.setJavaScriptEnabled
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值