How do i add a new line in html format in android?

2019-02-22 09:11发布

I have to add text to a button bolding the first line and unbolding the second but i cant figure out which new line character it is.

b.setText(Html.fromHtml("<b>" + st + "<\b>" + "\n" + cursor.getString(1)));

ive also tried

b.setText(Html.fromHtml("<b>" + st + "<\b>" + "<br/>" + cursor.getString(1)));

the second one works but both lines are bolded.

Thanks in advance

2条回答
贪生不怕死
2楼-- · 2019-02-22 09:21

wrong end tag:

b.setText(Html.fromHtml("<b>" + st + "</b>" + "<br/>" + cursor.getString(1)));
查看更多
狗以群分
3楼-- · 2019-02-22 09:43

Rather than using HTML to format your text (which is relatively slow) you could use Spans which give you much tighter control, and are more efficient. I wrote a blog post about the use of spans which may help you to get started.

查看更多
登录 后发表回答