sのインデックスがindexStartからindexEndの部分の背景色がbgcolorの文字列をtvにセットする
public void method(TextView tv,String s,int indexStart,int indexEnd,int bgcolor){
SpannableString spannable = new SpannableString(s);
spannable.setSpan(new BackgroundColorSpan(bgcolor), indexStart, indexEnd,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(spannable);
}
indexを変えてsetSpanを複数行書けば複数個所に着色できる。
BackgroundColorSpan を ForegroundColorSpanに置換すると文字に着色できる