一个TextView使用不同的颜色
生活随笔
收集整理的這篇文章主要介紹了
一个TextView使用不同的颜色
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個TextView使用不同的顏色:
textview中首先需要已經有內容了
public static void ColorFormatTextView(TextView tv,int color,String textStr){if (TextUtils.isEmpty(textStr) || tv == null|| TextUtils.isEmpty(tv.getText())) {return;}String showString = tv.getText().toString();int startIndex = showString.indexOf(textStr);if (startIndex < 0) {return;}ForegroundColorSpan style = new ForegroundColorSpan(color);SpannableStringBuilder formatted = new SpannableStringBuilder(showString);formatted.setSpan(style, startIndex, startIndex + textStr.length(),Spanned.SPAN_EXCLUSIVE_INCLUSIVE);tv.setText(formatted);}?
轉載于:https://www.cnblogs.com/qgli/p/4652016.html
總結
以上是生活随笔為你收集整理的一个TextView使用不同的颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 斗鱼直播源解析工具
- 下一篇: 2021年中国研究生数学建模竞赛D题——