[英]How to change decoration of a local HTML file to show it on the WebView in Android
In my android application I used to open a local HTML file like the one below: 在我的Android应用程序中,我曾经打开过一个本地HTML文件,如下所示:
mPath = ... myHTML.html
webView.loadUrl("file:///" + mPath);
Now I want to make some changes in my HTML file such as font size, align from left to right and right to left and ... I guess that I can do that by adding a CSS file to head of my HTML, but the problem is I have no idea how to access the source of my HTML file and convert it to string. 现在,我想在HTML文件中进行一些更改,例如字体大小,从左到右,从右到左对齐等等……我想我可以通过在HTML的头部添加CSS文件来做到这一点,但是问题是我不知道如何访问HTML文件的源并将其转换为字符串。
Is there any better way to change the decoration of a local HTML file? 有没有更好的方法来更改本地HTML文件的修饰? if not, how can I access the source of my HTML file?
如果没有,如何访问HTML文件的源?
OK I'm answering my own question. 好吧,我在回答我自己的问题。 I used Panos's answer on: https://stackoverflow.com/a/13357785/1572408
我在以下地方使用了Panos的答案: https : //stackoverflow.com/a/13357785/1572408
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
return sb.toString();
}
In onCreate()
: 在
onCreate()
:
File fl = new File(myLesson);
FileInputStream fin;
fin = new FileInputStream(fl);
String ret = convertStreamToString(fin);
ret = ret.replace("<body>","<body align='right' style='font-size:14pt;>");
webView.loadDataWithBaseURL("file:///android_asset/", ret, "text/html",
"UTF-8", "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.