我想自定义一个字符串,其结果将写入 TextView
但不起作用。我只想使用 html 标签为文本的某些部分着色,但它仍然是所有文本具有相同的颜色。这是我到目前为止所写的:
@Override
public String toString() {
return (Html.fromHtml("<font color=\"#e61624\">"+fromHour+"</font>")) + " " + from + " / " + toHour + " " + to;
}
谢谢
最佳答案
我不会在 toString()
方法中使用 Html.fromHtml
。
在toString()
中,只需返回相应的文本即可:
return "<font color=\"#e61624\">"+fromHour+"</font> " + from + " / " + toHour + " " + to;
然后调用:
textView.setText(Html.fromHtml(yourObject.toString());
关于java - Android 中的 HTML 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24159266/