我正在尝试使用此代码更改webview的文本颜色
String message ="<font color='white'>"+"<u>"+
"text in white"+ "<br>" +
"<font color='cyan'>"+"<font size='2'>"+
" text in blue color "+"</font>";
webview.loadData(message, "text/html", "utf8");
Run Code Online (Sandbox Code Playgroud)
但我有一些HTML页面.存储在我的SD卡中然后如何更改文本颜色..
我用
webViewRead.loadUrl(url);
Run Code Online (Sandbox Code Playgroud)
url是我文件的路径.
Fur*_*rqi 11
你必须像这样给出该文件的路径.
String extStorageDirectory = Environment.getExternalStorageDirectory()
.toString() + "/folder_name";
File directory = new File(extStorageDirectory);
File fileInDirectory = new File(directory,file_name.html);
//Read text from file
StringBuilder html_text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(fileInDirectory));
String line;
while ((line = br.readLine()) != null) {
html_text.append(line);
html_text.append('\n');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
Run Code Online (Sandbox Code Playgroud)
然后使用此HTML代码进行编辑
String message ="<font color='white'>"+"<u>"+"text in white"+ "<br>" +"<font color='cyan'>"+"<font size='2'>"+" text in blue color "+"</font>";
webview.loadData(message, "text/html", "utf8");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15144 次 |
| 最近记录: |