在WebView中更改HTML编程 [英] Changing HTML in a WebView programmatically

查看:193
本文介绍了在WebView中更改HTML编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用加载HTML网页的资产变成的WebView

I'm loading an html asset page into a WebView using

webMain.loadUrl("file:///android_asset/record.html");

这工作得很好,但在HTML中许多,我想从应用程序中使用的信息的地方。例如,HTML可以包含文本,上面写着[自定义]。有没有一种办法可以取代从应用程序传递信息字?

which works fine, but inside the html are a number of places where I'd like to use information from the app. For instance, the HTML may contain text that reads "[Custom]". Is there a way I can replace that word with information passed from the application?

推荐答案

其实我也不明白为什么record.html的文件大小会影响到code的maintainence。阅读HTML字符串(使用Java读取器类或什么都),从资产的HTML文件,使用的replaceAll函数与正则表达式替换所有的[自定义]中的HTML文件。在HTML多久是真的不应该影响你如何保持code。它应该是一个性能问题,或串真的长超过了Java字符串限制。

Actually I do not understand why the file size of record.html will affect maintainence of the code. Read the html string (using Java reader class or what ever) from the html file in asset, use replaceAll function with Regex to replace all the [Custom] in the html file. How long the html is should not really affect how you maintain the code. It should rather be a performance problem, or the string is really really long that exceeds the java String limit.

一些code之前,我已经使用:

some code I have used before :

InputStream is = getApplicationContext().getAssets().open("details/product_jsmodify.html");
Reader r = new InputStreamReader(is);
String details = Utils.readertoString(r);
details = details.replace("%product_name%",productName );

utils的是我班做转换为字符串。我不使用正则表达式作为这里我只更换一次话。然后,我喜欢做卡塔加载字符串。这是很干净的,我想。

Utils is my class doing the conversion to string. I am not using Regex here as I am only replacing word for once. Then I load the string like Cata does. It is quite clean I suppose.

这篇关于在WebView中更改HTML编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆