[英]How can I use <img> with a local image on Android?
Using <img>
with the src
, a local file works fine on a PC.将
<img>
与src
,本地文件可以在 PC 上正常工作。 But on Android 7 it doesn't get displayed;但在 Android 7 上它不会显示; instead a no photo icon is displayed.
而是显示无照片图标。 How can I solve this?
我该如何解决这个问题?
<img src="photo.png">
(The photo.png
is placed in the same folder as the .html
file.) (
photo.png
与.html
文件放在同一文件夹中。)
You have to declare the path of the photo:您必须声明照片的路径:
<img sc = " xxxpathxxx/"photo.png">
Else, make a separate image folder and call it.否则,创建一个单独的图像文件夹并调用它。
The issue with this is how Webview works with local files.问题在于Webview 如何处理本地文件。 File paths aren't the same as your PC Google Chrome paths where you can drag an HTML file to the browser and have it be loaded in a certain path, and because of that photo.png doesn't direct anywhere.
文件路径与您的 PC 谷歌浏览器路径不同,您可以在其中将 HTML 文件拖到浏览器并在特定路径中加载,因此 photo.png 不会指向任何地方。
Instead, you need to use the file:// schema to access local files.相反,您需要使用file:// 架构来访问本地文件。 Regardless of whether photo.png is local or an Internet resource, you'll need to use photo.png's absolute path, eg:
无论 photo.png 是本地资源还是 Internet 资源,您都需要使用 photo.png 的绝对路径,例如:
http://localhost/path/to/photo.png
http://www.mywebsite.com/path/to/photo.png
file://data/local/tmp/photo.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.