实现方法:使用SpannableStringBuilder方法即可实现
String hello=“hello" int a= hello.indexOf("ll"); int b= hello.indexOf("o"); SpannableStringBuilder builder = new SpannableStringBuilder(hello); builder.setSpan(new ForegroundColorSpan(Color.RED), a, b, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);//指定索引a到b-1的字符 et_hello.setText(builder);
参考链接
https://blog.csdn.net/xuwenneng/article/details/51027625?locationNum=10&fps=1