1

WebView を使用し、WebView.LoadData(); を使用して html データをレンダリングするアクティビティがあります。ほとんどの html データでは問題なく動作しますが、Html に "
& # 6 0 ; p & # 6 2 ; & # 6 0;"のような引用符が含まれている場合 WebView はその html を適切にデコードできず、WebView に html タグを表示します。

私はこのコードを試しました:

    for(char c: rssFeed.getDescription().toCharArray()){

        switch (c) {
         case '#':  htmlBuffer.append("%23"); break;
         case '%':  htmlBuffer.append("%25"); break;
         case '\'': htmlBuffer.append("%27"); break;
         case '?':  htmlBuffer.append("%3f"); break;     
         case '&':  htmlBuffer.append("%26"); break;
         case ':':  htmlBuffer.append("%3A"); break;
         case ';':  htmlBuffer.append("%3B")  ;break;
         case '/': htmlBuffer.append("%2F"); break;


         default:
           htmlBuffer.append(c);
           break;
        }
    }

しかし、役に立ちません。

4

1 に答える 1

0

Base64 を使用してすべてをエンコードしてみてください。以下が機能するはずです。

String content  = "html content";  // the html data
String base64 = android.util.Base64.encodeToString(data.getBytes("UTF-8"), android.util.Base64.DEFAULT);
webView.loadData(base64, "text/html; charset=utf-8", "base64");
于 2012-09-12T13:27:13.297 に答える