0

如何将动态字符串传递给 HTML 文档以替换不同的占位符?

即 HTML 占位符 %title% 被标题的动态字符串替换

4

1 回答 1

0

在 HTML 中标记占位符 - 然后我会加载我的 HTML:%NAME%

String template = Utils.inputStreamToString(assets.open("html/template.html"));

然后我会用我想要的东西替换所有动态部分:

String data = template.replaceAll("%NAME%", "Alice McGee");

然后我会将它传递给我的 webView!

WebView webView = new WebView(this);
webView.loadDataWithBaseURL("file:///android_asset/html/", data, "text/html", "utf-8", null);
于 2012-08-14T05:40:55.110 回答