【问题标题】:Android WebView loadDataWithBaseURL not work in Android 4.0.3(api15)Android WebView loadDataWithBaseURL 在 Android 4.0.3(api15) 中不起作用
【发布时间】:2014-08-15 04:02:20
【问题描述】:

我使用此代码将图片从可绘制对象加载到我的 WebView。

String s ="<html><body style='margin: 0; padding: 0'><IMG  width='100%' height='100%' src='picturename'><body><html>";
webview.loadDataWithBaseURL("file:///android_res/drawable/", s, "text/html", "UTF-8", null);

并在 2 台设备上进行测试。

1.HTC Sensation XE With Beats Audio Z715e (Android 4.0.3(api15))----->不工作

2.ASUS fonepad7 K00Z (Android 4.4.2(api19))--------------------------->工作很好

如何解决

编辑

哦!!!我可以解决它的

我很笨。

问题出在图片名称中。

在 android 4.0.3 中需要文件类型(例如:“picturename.png”),但在 android 4.4.2 中不需要。

它可以使用没有文件类型的文件名(例如:“图片名”)。

【问题讨论】:

  • 我可以解决它。请在我的编辑中查看。

标签: android webview android-webview


【解决方案1】:

请试试这个

String s ="<html><body style='margin: 0; padding: 0'><IMG  width='100%' height='100%' src='file:///android_res/drawable/picturename'><body><html>";

webview.loadDataWithBaseURL(null, s, "text/html", "UTF-8", null);

【讨论】:

  • 如果你的文件有扩展名,你应该使用它作为示例图片名.png
猜你喜欢
  • 2017-10-08
  • 2021-08-30
  • 1970-01-01
  • 2013-04-03
  • 2013-09-13
  • 2012-08-18
  • 1970-01-01
  • 2016-09-22
  • 1970-01-01
相关资源
最近更新 更多