的WebView无法正常加载资产 [英] WebView not loading Assets correctly

查看:126
本文介绍了的WebView无法正常加载资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我用来显示一些存储在资产/ 目录HTML /图像文件的WebView。我能够拥有的WebView负载和HTML页面的罚款:

I have a WebView that I'm using to display some html/image files stored in the assets/ directory. I'm able to have the WebView load and html page fine with:

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

String data = StaticFunctions.inputStreamToString(getAssets().open("ContentRoot/SubDir/file.html"));
mWebView.loadDataWithBaseURL("file:///android_asset/ContentRoot/SubDir/file.html", data, "text/html", "UTF-8", null);

我遇到的问题是,有图像在HTML这样的:

The problem I'm having is that there are images in the HTML like:

<img src="../Photos/image.jpg" alt="whatever" />

和,而不是装载从资产/ ContentRoot /图片/ image.jpg的它试图从资产/图片/ image.jpg文件加载它们

and instead of loading from assets/ContentRoot/Photos/image.jpg it's trying to load them from assets/Photos/image.jpg.

为什么试图从错误的(相对)位置加载它们,我能做些什么来解决这个问题?

Why is it trying to load them from the wrong (relative) location and what can I do to correct the issue?

推荐答案

哦,伙计......我在这里错过了一些愚蠢的事。在HTML只是完全错误和图片目录不是一个级别从源头上。很抱歉的混乱。

Oh man... I missed something stupid here. The html was just flat-out wrong and the Photos directory wasn't one level "up" from the source. Sorry for the confusion.

这篇关于的WebView无法正常加载资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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