像这样使用 WebView 可以吗?

发布于 2024-12-27 10:18:14 字数 346 浏览 1 评论 0原文

我在 src 中使用可绘制对象作为 webview 中的标记,这可行吗?

     mWebView.loadDataWithBaseURL("","<table width=\"100%\"><tr><td style=\"text-
     align:center; background-color:grey;\"><img src=\""+R.id.button+"\"/></td></tr>                
     </table>"+Question, "text/html", "utf-8", "");

I am using drawables in src for tag in webview would this work?

     mWebView.loadDataWithBaseURL("","<table width=\"100%\"><tr><td style=\"text-
     align:center; background-color:grey;\"><img src=\""+R.id.button+"\"/></td></tr>                
     </table>"+Question, "text/html", "utf-8", "");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不…忘初心 2025-01-03 10:18:14

我在 src 中使用可绘制对象作为 webview 中的标记,这可行吗?

绝对不是。 HTML 需要图像的 URL。更不用说您指定的是小部件 ID,而不是可绘制资源。

先生,确实很有帮助,但它在模拟器上正常工作,但在设备上却无法正常工作。您知道如何解决它吗?

也许您的设备较旧 - Clayson 先生链接的问题的一个答案表明 file:///android_res/ URL 仅适用于 Android 2.2 及更高版本。

然而,android.resource方案已经存在了更长的时间:

android.resource://[package]/[res type]/[res name]

例如:

android.resource://this.is.my.package/drawable/button

我还没有在 WebView 中尝试过这个,但值得一试。

I am using drawables in src for tag in webview would this work?

Absolutely not. HTML expects URLs for images. Not to mention that you are specifying a widget ID, not a drawable resource.

sir that really helped but it is working correctly on emulator but not on the device .Do you know how to solve it?

Perhaps your device is older -- one answer on the question that Mr. Clayson linked to suggests that file:///android_res/ URLs only work on Android 2.2 and higher.

However, the android.resource scheme has been around longer:

android.resource://[package]/[res type]/[res name]

e.g.:

android.resource://this.is.my.package/drawable/button

I have not tried this in WebView, but it is worth a shot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文