引用图像资产HTML不工作 [英] Referencing image in assets from HTML not working

查看:118
本文介绍了引用图像资产HTML不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android应用程序中显示的web视图的图像。图像存在于我的Andr​​oid项目的资产文件夹。之后,HTML编程方式建立并拥有这一形象裁判在里面:

I'm trying to display an image in a WebView in an Android app. The image exists in the assets folder of my Android project. The HTML is programmatically built and has this image ref in it:

中的HTML加载到web视图使用:

The HTML is loaded into the WebView using:

webView.loadDataWithBaseURL(urlStr,的htmlText,text / html的,UTF-8,urlStr);

webView.loadDataWithBaseURL( urlStr, htmlText, "text/html", "utf-8", urlStr );

urlStr =寻找其他资源需要一个基本URL。 的htmlText =该程序生成的HTML

urlStr = a base url needed to find other resources. htmlText = the programmatically generate HTML

本的WebView加载HTML罚款,但图像显示为失踪。我已验证的形象存在于在资产位置。尽管如此,它不会出现在web视图。

The WebView loads the HTML fine, but the image is displayed as "missing". I have verified that the image exists at that location in the assets. Nevertheless it does not appear in the WebView.

我见过无数的帖子和教程说,这应该工作,但它不适合我。这是一个3.2的Andr​​oid平板电脑。任何人都知道,如果这仅适用于某些版本的Andr​​oid?为什么它不能在我的情况下工作,有什么想法?谢谢你。

I have seen numerous postings and tutorials saying that this should work, but it doesn't for me. This is on a 3.2 Android tablet. Anyone know if this only works on some versions of Android? Any thoughts about why it doesn't work in my case? Thanks.

推荐答案

好了,我终于想通了这一点。显然是在某个地方在它失败,如果图像路径中有空格的安卓code的错误。所以:

OK, I finally figured this out. Apparently there is a bug somewhere in the Android code where it fails if the image path has a space in it. So:

<img src="file:///android_asset/SkyInfo/images/Deep Sky/M13-Misti.jpg">

将无法加载图像。如果您将其更改为:

will fail to load the image. If you change it to:

<img src="file:///android_asset/SkyInfo/images/DeepSky/M13-Misti.jpg">

将工作(假设你已经改名的目录)。

it will work (assuming you've renamed the directory).

请注意:

  • 这只是一个问题来自资产读书的时候。
  • 似乎是一个问题与Android 4.x的我已在4.0.4和4.3版本中遇到过这个问题,但空间工作的很好的2.3.x版本。

来吧谷歌,在目录名称空间中已经屡见不鲜了15年。获取的程序。

Come on Google, spaces in directory names have been common for 15 years. Get with the program.

这篇关于引用图像资产HTML不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆