set emoji text BackgroundColorSpan not work
Liveinadream opened this issue · 2 comments
Liveinadream commented
use system can set BackgroundColorSpan(),but no working on self.What is the solution.
Liveinadream commented
here is my code
`
public CharSequence buildSpannableStringBackground(CharSequence content, CharSequence keyword) {
if (TextUtils.isEmpty(content)) {
return new SpannableStringBuilder("");
}
if (TextUtils.isEmpty(keyword)) {
return content;
}
SpannableStringBuilder spannableString = new SpannableStringBuilder(content);
String lowerContent = content.toString().toLowerCase();
String lowerKeyword = keyword.toString().toLowerCase();
int index = lowerContent.indexOf(lowerKeyword);
if (index != -1) {
int color = getApplicationContext().getResources().getColor(R.color.yc_color_FFFA00);
while (index != -1) {
spannableString.setSpan(new BackgroundColorSpan(color), index, index + lowerKeyword.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
index = lowerContent.indexOf(lowerKeyword, index + 1);//从这个索引往后开始第一个出现的位置
}
}
return spannableString;
}
`
Liveinadream commented