在字符串的TextView HTML标签 [英] HTML tags in string for TextView

查看:131
本文介绍了在字符串的TextView HTML标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我把简单的HTML格式标记,例如< B> ...< / B>成字符串资源,并显示在字符串中的一个TextView,预期格式应用于。但是,我怎么能做到这一点,如果我建立我自己的字符串并显示它?如果我像做字符串str =这为< B>大胆< / B>中。;,实际的标签得到显示 - 不是预期的粗体

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?

推荐答案

您必须使用<一个href="http://developer.android.com/reference/android/text/Html.html#fromHtml%28java.lang.String%29">Html#fromHtml

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

这篇关于在字符串的TextView HTML标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆