Android实用技巧.视图技巧(一)

来源:互联网 发布:淘宝阿迪旗舰店是正品 编辑:程序博客网 时间:2024/05/17 01:15

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));    }


0 0
原创粉丝点击