【转】android-修改TextView中部分文字的颜色
生活随笔
收集整理的這篇文章主要介紹了
【转】android-修改TextView中部分文字的颜色
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
textView = (TextView) findViewById(R.id.textview);SpannableStringBuilder builder = new SpannableStringBuilder(textView.getText().toString());//ForegroundColorSpan 為文字前景色,BackgroundColorSpan為文字背景色ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);ForegroundColorSpan whiteSpan = new ForegroundColorSpan(Color.WHITE);ForegroundColorSpan blueSpan = new ForegroundColorSpan(Color.BLUE);ForegroundColorSpan greenSpan = new ForegroundColorSpan(Color.GREEN);ForegroundColorSpan yellowSpan = new ForegroundColorSpan(Color.YELLOW);builder.setSpan(redSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);builder.setSpan(whiteSpan, 1, 2, Spannable.SPAN_INCLUSIVE_INCLUSIVE);builder.setSpan(blueSpan, 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);builder.setSpan(greenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);builder.setSpan(yellowSpan, 4,5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);textView.setText(builder);
?
轉載于:https://www.cnblogs.com/butterfly-clover/p/5481545.html
總結
以上是生活随笔為你收集整理的【转】android-修改TextView中部分文字的颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL技术内幕读书笔记(一)——My
- 下一篇: 编写一个爬虫类库——(一)想法