Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从HTML文件中的android资产文件夹读取文件?_Android_Html - Fatal编程技术网

如何从HTML文件中的android资产文件夹读取文件?

如何从HTML文件中的android资产文件夹读取文件?,android,html,Android,Html,我正在为android制作一个基于HTML的应用程序。我通过以下方式显示html文件:“file:///android_asset/index.html“ 但是我想在html文件中加载本地图像文件或字体,并且我已经将它们加载到了asset文件夹中 作为源链接执行此操作不起作用 <img src="file:///android_asset/p100.jpg" style="width:85px"> 那么,如何在html中使用本地资产文件,以便在我的应用程序中显示它们?您的资产文

我正在为android制作一个基于HTML的应用程序。我通过以下方式显示html文件:
“file:///android_asset/index.html“

但是我想在html文件中加载本地图像文件或字体,并且我已经将它们加载到了asset文件夹中

作为源链接执行此操作不起作用

<img src="file:///android_asset/p100.jpg" style="width:85px">


那么,如何在html中使用本地资产文件,以便在我的应用程序中显示它们?

您的资产文件夹必须具有名称“资产”,因为它是以这种方式映射的

file:///android_asset/ =>“资产”文件夹

另外:如果像这样加载
WebView
数据

webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html; charset=UTF-8", null, null);
你的img标签变成了这个

<img src="p100.jpg" style="width:85px">


因为基本url将成为您的资产文件夹。

您可能会更幸运地从“相对”位置加载图像:只需
src=“p100.jpg”