android spannableString 替换 textview 中部分文字

时间:2015-03-26 20:30:38   收藏:0   阅读:689

参考:http://www.cnblogs.com/bill-joy/archive/2012/03/24/2415539.html

http://blog.sina.com.cn/s/blog_465918fc0101ehf2.html

 

//方法一:
textView.setText(Html.fromHtml("<font color=\"#ff0000\">红色</font>其它颜色"));
//方法二:
String text = "获得银宝箱!";
SpannableStringBuilder style=new SpannableStringBuilder(text); 
style.setSpan(newBackgroundColorSpan(Color.RED),2,5,Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置textview的背景颜色

style.setSpan(newForegroundColorSpan(Color.RED),0,2,Spannable.SPAN_EXCLUSIVE_INCLUSIVE); //设置指定位置文字的颜色
textView.setText(style);



原文:http://www.cnblogs.com/wjw334/p/4369558.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!