开发者

HTML tags in string for TextView

If I put simple HTML formatting tags, such as <b>...</b> into a string resource and display the string in a TextView, the expected formatting is applied. But how can I do this if I build up my own String and display it? If I do something开发者_开发问答 like String str = "This is <b>bold</b>";, the actual tags get displayed -- not the expected bolding.

Do I have to run the string through some other method to cause the tags to be recognized as tags?


You have to use Html#fromHtml

String input = "<b>bold</b>";
myTextView.setText(Html.fromHtml(input));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜