2

HTML文字列の部分文字列の正当性を揃える必要があるアプリを開発しています。

問題: 次のコードを使用して、webview を使用して HTML テキストの正当性を設定しました。

String htmlText = "<html><body style=\"text-align:justify\"> %s </body></Html>";
WebView webView = new WebView(SubProducts.this);
webView.loadData(String.format(htmlText, description), "text/html", "utf-8");

しかし、次のように部分文字列に同じアイデアを設定すると:

String htmlText = "<html><body style=\"text-align:justify\"> %s </body></Html>";
WebView webView = new WebView(SubProducts.this);
webView.loadData(String.format(htmlText, description.substring(1,170)), "text/html", "utf-8");

出力テキスト html text(

<html><body style=\"text-align:justify\"> %s </body></Html>) 

これを達成する方法.誰でも私を助けることができますか? 前もって感謝します。

4

2 に答える 2

1

Substring を見つけて WebView 内にロードすると、うまくいきます。正当化のために、既製のコードを以下に示します

    public static void loadHtmlContentForAboutUs(WebView view, String appendText) {
    String s = "<html><head><style type='text/css'>body {margin:0px;color:707070;"
            + "text-align: justify;}</style></head><body>"
            + appendText
            + "</body></html>";

    view.loadDataWithBaseURL("", s, "text/html", "utf-8", null);
    view.setBackgroundColor(Color.TRANSPARENT);
}
于 2013-04-16T06:51:38.077 に答える