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

半腔热情 提交于 2020-01-11 09:06:48

问题


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


回答1:


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.




回答2:


wrong end tag:

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


来源:https://stackoverflow.com/questions/6342042/how-do-i-add-a-new-line-in-html-format-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!