是否有可能在Android的loadDataWithBaseURL()方法显示图像?有可能、图像、方法、loadDataWithBaseURL

2023-09-06 13:54:27 作者:我的期待死掉了

我试图显示与 loadDataWithBaseURL()方法机器人。

I'm trying to display the content of a html file with the loadDataWithBaseURL() method in android.

我只是有一个包含在一个字符串中的HTML文件的数据称为源,然后我把它传递给方法的字符串。

I just have a String that contains the Html file data in one String called source and I then pass this to the method.

对于例如

String source; //contain html tags with images
View.loadDataWithBaseURl(null,source,"text/html","UTF-8","about:blank");

在视图中显示的数据是好的。 我的问题是,如果我的HTML文件包含的任何图像,然后我可以不显示呢? 我该怎么办呢?

The data displayed in view is fine. My problem is if my html file contains any images then I couldn't displayed it? how can I do that?

推荐答案

你可以做到这一点,如果源中的图像用于SRC的相对位置,那么你需要的的baseUrl设置为基地里的图像将设。例如,如果你从源加载谷歌的主页,它是这样的:

you can do it, if the images in the source use relative locations for the src then you need to set the baseUrl to the "base" of where the images would be located. for example, if you were loading google's home page from the source, it would look like this:

View.loadDataWithBaseURI("http://google.com",source,"text/html","UTF-8","about:blank");

这告诉那里的图像将被从加载web视图。

That tells the webview where the images will be loaded from.

作为一个方面说明,我不认为文件://URI的作品在网络视图中,出于安全原因,

As a side note, I do not think "file://" URIs works in the web view, for security reasons.