【问题标题】:Can I link .png images I have stored in res/mipap to html files I have stored in android_asset, so WebView shows both text and images in an html file?我可以将我存储在 res/mipap 中的 .png 图像链接到我存储在 android_asset 中的 html 文件,以便 WebView 在 html 文件中显示文本和图像吗?
【发布时间】:2022-01-23 18:56:56
【问题描述】:

我有一个使用 WebView 功能的 Android 应用程序,它会在出现提示时从本地主机打开我的应用程序内的 html 文件,这些文件已存储在 android_asset 文件夹中。但是,WebView 函数只显示 html 文件中的文本,它不显示我链接到 html 文档代码中的图像,这些图像存储在 res/mipmap 中。当我使用 WebView 打开 html 文件时,我的应用程序可以同时显示文本和图像,这对我来说很重要。将 html 文件和图像存储在一个位置也很重要,这意味着它们将被添加到可安装程序中(这样用户就不必连接到互联网来使用应用程序或在他们周围移动任何文件) .是否可以将存储在本地主机上的图像链接到 android_asset 或 res/mipmap 中,以便在 WebView 中打开 html 文件时可以同时看到文本和图像? 失效的图片链接在 res/mipmap 中,它是:img src = "file:///mipmap-hdpi/car.png" alt = "Test Image"

【问题讨论】:

    标签: html android-studio webview localhost android-mipmap


    【解决方案1】:

    我在 android_asset 中创建了一个名为 imagepng 的新文件夹。然后,我将 .png 文件放在此文件夹中(因此 html 文件中图像的链接看起来像 )。 html 文件现在从这个地方调用 .png 图像,我可以在应用程序上看到它。我还不知道这是否使它成为可安装的,因此它可以从本地运行 智能手机............我最初的错误是试图将图像直接放入 android_asset 因为它不允许这样做。

    【讨论】:

      猜你喜欢
      • 2016-10-27
      • 2014-12-05
      • 2014-12-19
      • 2021-05-20
      • 2023-03-06
      • 1970-01-01
      • 2021-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多