安卓添加图片从绘制到的WebView图片、WebView

2023-09-12 09:10:45 作者:空城旧巷°一世悲涼

我想要的东西:

s="
<body>

<img src='"+R.drawable.picture+"'>

</body>";

我怎样才能做到这一点?

How can I do this?

推荐答案

您只能做这样的事情,如果我们的形象是在你的 /资产文件夹。此外,还必须加载HTML用的baseUrl这是在你的资产的文件夹。

You can only do such a thing if our image is inside your /assets folder. Also, you must load your html with a baseUrl that's inside your assets folder.

您可以使用 WebView.loadUrl() WebView.loadDataWithBaseURL()

webView.loadUrl(文件:///android_asset/file.html);

webView.loadUrl("file:///android_asset/file.html");

webView.loadDataWithBaseURL("file:///android_asset/", "<img src='file.jpg' />", "text/html", "utf-8", null);

(file.jpg应该在你的资产文件夹)

(file.jpg should be inside your assets folder)