如何以编程方式设置/编辑webview的内容

时间:2011-06-01 18:55:29

标签: android

有没有办法可以编辑内容以通过java添加或从头开始创建?我找不到任何例子。

2 个答案:

答案 0 :(得分:64)

您应该查看WebView文档here

在那里有大量的信息,你会发现:

// OR, you can also load from an HTML string:
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
webview.loadData(summary, "text/html; charset=utf-8", "utf-8");
// ... although note that there are restrictions on what this HTML can do.
// See the JavaDocs for loadData() and loadDataWithBaseURL() for more info.

非常靠近页面顶部。

答案 1 :(得分:2)

WebView.loadData可以传递一个直接的HTML字符串。我使用了一个“页面”,我在我的应用程序中从头开始创建,只是用HTML格式化