rockerhieu / emojicon

A library to show emoji in TextView, EditText (like WhatsApp) for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

set emoji text BackgroundColorSpan not work

Liveinadream opened this issue · comments

use system can set BackgroundColorSpan(),but no working on self.What is the solution.

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;
}

`