Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set emoji text BackgroundColorSpan not work #191

Open
Liveinadream opened this issue Oct 20, 2019 · 2 comments
Open

set emoji text BackgroundColorSpan not work #191

Liveinadream opened this issue Oct 20, 2019 · 2 comments

Comments

@Liveinadream
Copy link

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

@Liveinadream
Copy link
Author

Liveinadream commented Oct 20, 2019

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
Copy link
Author

Screenshot_2019-10-20-22-15-33-218_com rockerhieu
Screenshot_2019-10-20-22-16-43-345_com rockerhieu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant