美文网首页
android TextView改变部分字体颜色

android TextView改变部分字体颜色

作者: 梦沉薇露 | 来源:发表于2016-06-19 21:30 被阅读0次
    
     textview = (TextView) findViewById(R.id.textview);
            SpannableStringBuilder ssbuilder = new SpannableStringBuilder(textview.getText().toString());
            //ForegroundColorSpan--文字前景色,BackgroundColorSpan--文字背景色
            ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);
            ssbuilder.setSpan(yellowSpan, 11,15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            textview.setText(ssbuilder);
    

    效果如下:


    QQ截圖20160619212930.png

    相关文章

      网友评论

          本文标题:android TextView改变部分字体颜色

          本文链接:https://www.haomeiwen.com/subject/shgbdttx.html