Html.fromHtml()使用技巧
长用标签:
// <font>: 设置颜色和字体。
// <big>: 设置字体大号
// <small>: 设置字体小号
// <i><b>: 斜体粗体
// <a>: 连接网址
// <img>: 图片
特别注意:如图中文本text2, setText中拼接文本,html效果无效
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_text_html);
htext1 = (TextView) findViewById(R.id.text1);
htext2 = (TextView) findViewById(R.id.text2);
htext3 = (TextView) findViewById(R.id.text3);
String text1 = "<font color='#FDBD23'>风晴03</font>";
String text2 = "账号:<font color='#FDBD23'>风晴03</font>";
String text3 = "<big><big><u>下划线</u></big></big>";
htext1.setText(Html.fromHtml(text2));
//setText中拼接文本,html效果无效
htext2.setText("账号:"+Html.fromHtml(text1));
//参数flags: 文本显示模式,加上就报错。大神看见 求告知
htext3.setText(Html.fromHtml(text3));
}