如何在android中设置webview的文本颜色
我正在尝试使用此代码更改webview的文本颜色如何在android中设置webview的文本颜色,android,webview,Android,Webview,我正在尝试使用此代码更改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", "ut
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");
url是我的文件的路径。您必须这样给出该文件的路径
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
}
然后使用此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");
String message=“+”+”白色文本“+”
“+”+”+”蓝色文本“+”;
loadData(消息,“text/html”,“utf8”);
将文件路径设置为
String htmlPath = "file:///mnt/sdcard/test/11.html";
String baseUrl = "file:///mnt/sdcard/test/";
webView.loadDataWithBaseURL(baseUrl, message, "text/html", "utf-8", null);
webView.loadUrl(htmlPath);
htmlDetail=dbValues.getContent(3);
tvDescription3.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
字符串finalHtml=“”
+“li{color:#00f}span{color:#000}”
+ ""
+ ""
+HTMLDEAIL
+ "";
tvDescription3.loadData(finalHtml,“text/html;charset=UTF-8”,null);
要更改网络视图的背景色,有一种标准方法:
mWebView.setBackgroundColor(Color.Black);
要更改WebView的文本字体颜色,没有标准方法: 您可以通过html代码更改字体,也可以执行以下操作:
htmlData="<font color='black'>" + htmlData + "</font>";
mWebView.loadDataWithBaseURL(null, htmlData, "text/html", "UTF-8", null);
htmlData=”“+htmlData+”;
loadDataWithBaseURL(null,htmlData,“text/html”,“UTF-8”,null);
参考此内容,但我希望显示html页面而不是文本..wv.loadDataWithBaseURL(“,html,mimeType,encoding,”);在此方法中,我应该将路径(文件)plz dis-crib放在何处。如果要加载html文件,请将html文件放在assets文件夹中。请参阅此链接
mWebView.setBackgroundColor(Color.Black);
htmlData="<font color='black'>" + htmlData + "</font>";
mWebView.loadDataWithBaseURL(null, htmlData, "text/html", "UTF-8", null);