android - 如何在android中离线加载网页

标签 android webview

<分区>

我正在尝试在我的应用程序中加载我正在使用的应用程序的条款和条件。客户向我提供了一个包含条款和条件的 html 文件,但我没有任何类型的服务器访问权限。所以从技术上讲,应用程序需要随身携带该文件。我已经完成了 WebView ,其中在线数据显示在 WebView 中,但我对这种情况没有任何了解。我知道我在这里遗漏了一个愚蠢的观点。请帮忙

我的布局文件是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_vertical|center_horizontal"
    android:orientation="vertical" >

    <WebView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</LinearLayout>

最佳答案

文件上要用到的任何文档,一般都放在assets文件夹中。引用this documentation .这是一个工作 fragment 。

try {
            WebView mWebView = null;
            mWebView = (WebView) findViewById(R.id.webview);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.loadUrl("file:///android_asset/index.html"); 
        } catch (Exception e) {
            // TODO: handle exception
            this.finish();
        }

关于android - 如何在android中离线加载网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23854227/

相关文章:

android - 在 WebView 中禁用邮寄地址的自动链接

react-native - 确定是否在 React Native WebView 中运行

android - 导出的 SQLite 数据库不是最新的

java - Android - Service、IntentService、JobIntentService - 如果应用程序被杀死,它们就会停止

java - 如何在我的 Android Studio 项目上使用代号 one 迁移工具?

java - Android 自定义事件监听器

android - 如何将 Google Maps Android API v2 标记链接到对象

android - Flutter中有WebView吗?

javascript - JavescriptInterface 和线程不返回主线程

javascript - 执行 javascript 并返回响应 (JavaFX/Swing)