Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 2.3 webview loadData只显示编码字符_Android_Android Webview - Fatal编程技术网

Android 2.3 webview loadData只显示编码字符

Android 2.3 webview loadData只显示编码字符,android,android-webview,Android,Android Webview,我正在尝试使用带有loadData的webview来显示图像: String data = "<html><head><title>Photo</title></head>"; data = data + "<body><center><img width=\"100%\" src=\"" + imageUrl + "\" /></center></b

我正在尝试使用带有loadData的webview来显示图像:

        String data = "<html><head><title>Photo</title></head>";
        data = data + "<body><center><img width=\"100%\" src=\"" + imageUrl + "\" /></center></body></html>";

        imageWebView.getSettings().setLoadWithOverviewMode(true);
        imageWebView.getSettings().setUseWideViewPort(true);
        imageWebView.getSettings().setBuiltInZoomControls(true);
        imageWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        imageWebView.setScrollbarFadingEnabled(false);
        imageWebView.loadData(data, "text/html", "UTF-8");
        imageWebView.setBackgroundColor(0x00000000);
String data=“Photo”;
数据=数据+“”;
imageWebView.getSettings().SetLoadWithOverview模式(true);
imageWebView.getSettings().setUseWideViewPort(true);
imageWebView.getSettings().SetBuilTinZoomControl(true);
imageWebView.setScrollBarStyle(WebView.SCROLLBARS\u外部\u覆盖);
imageWebView.SetScrollBarFadinEnabled(假);
加载数据(数据,“文本/html”、“UTF-8”);
imageWebView.setBackgroundColor(0x00000000);

在4.1模拟器中,这一切正常,我可以看到图像。在2.3中,它只显示编码的html代码。

这似乎是由以下原因造成的:如果提供的数据中有任何百分比,则数据将被解释为URL

如错误报告中所述,一个已知的解决方法是将所有
%
替换为
%

a中建议了另一个似乎效果很好的解决方法,该方法还应涵盖可能导致相同问题的任何其他字符:

mWebView.loadData(URLEncoder.encode(data,"utf-8").replaceAll("\\+"," "), "text/html", "utf-8");

你有没有弄清楚是什么引起的?我有一些HTML没有在4.0之前的webview中呈现。不幸的是,我还不知道为什么会发生这种情况。如果你的imageUrl参数有顽皮的字符(对url来说顽皮?,%等),那么你应该对进入loadData的所有数据进行url编码,如下所示:urlcoder.encode(data.replaceAll(“\\+”,”)