【问题标题】:Load local html file in webview android在webview android中加载本地html文件
【发布时间】:2014-02-28 17:40:08
【问题描述】:

我正在尝试在 android 的 web 视图中加载 html 文件的内容。但是,它给了我“网页不可用错误”。如果我尝试使用 google 或 yahoo 等网站,它们就可以工作。

html 文件在 src > main > assests > index.html 下

谁能帮我解决这个问题。谢谢。

以下是我的代码:

setContentView(R.layout.activity_main);

WebView mWebView;
mWebView = (WebView) findViewById(R.id.activity_main_webview);

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);

mWebView.loadUrl("file:///android_asset/index.html");

XML 文件:

<WebView
    android:id="@+id/activity_main_webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

【问题讨论】:

  • 我希望你的资产文件夹没有真正命名为assests

标签: android html webview android-studio local


【解决方案1】:

html 文件应放在assets 文件夹中(注意拼写),该文件夹将属于您项目的根目录。

所以移动

src/main/assests/index.html

assets/index.html

在 Android Studio 项目中使用此文件夹:

/app/src/main/assets/index.html

【讨论】:

    猜你喜欢
    • 2014-01-19
    • 1970-01-01
    • 2022-06-25
    • 1970-01-01
    • 1970-01-01
    • 2011-05-31
    • 2020-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多