我想知道在Java中是否可以改变字符串中的文本颜色?
我在我的警告对话框中有一段文本,基本上我喜欢的是所有粗体()的文本,我希望这些文本的颜色是红色的,而其余的文本是黑色的。这是可能的吗?如果可能,如何实现?
alertDialog.setMessage(Html.fromHtml("<b>Number of Human Players Required:</b>" + "<br/><br/>" +
" 2" + "<br/><br/>" +
"<b>Objective Of The Game:</b>" + "<br/><br/>" +
"The objective of Tic Tac Toe is to get three in a row either in a vertical line, " +
"horizontal line or diagonal line."
)
谢谢,
发布于 2018-06-04 03:08:44
你可以这样做:
String s = "<font color='red'><b>Number of Human Players Required:</b></font>"
+ "<br/><br/>" + " 2" + "<br/><br/>"
+ "<font color='blue'><b>Objective Of The Game:</b></font>"
+ "<br/><br/>"
+ "<font color='yellow'>The objective of Tic Tac Toe is to get three in a row either in a vertical line, "
+ "horizontal line or diagonal line.</font>"
alertDialog.setMessage(Html.fromHtml(s));
https://stackoverflow.com/questions/50669943
复制相似问题