1

I was reading this awesome blog and Contact Bubble EditText to add bubble in TextView. In my situation I do have Editable instead of TextView. Here is my code:

private void setSpans(Editable s, @ColorInt int backgroundColor) {
  BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class);
  String[] words;
    if (s.toString().endsWith(" ")) {
        words = (s.toString() + "X").split("\\s");
    } else {
        words = s.toString().split("\\s");
    }


    int completedWordsCount = words.length - 1;
    if (spans.length != completedWordsCount) {
        for (BackgroundColorSpan span : spans) {
            s.removeSpan(span);
        }

        int currentIndex = 0;
        for (int i = 0; i < words.length - 1; i++) {
            s.setSpan(new BackgroundColorSpan(backgroundColor), currentIndex, currentIndex + words[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            currentIndex += words[i].length() + 1;
        }
    }
}

Reference of the code

How can I make this Editable field work like above pasted blog. Is there any way to add oval shape in s.setSpan(new BackgroundColorSpan(backgroundColor), currentIndex, currentIndex + words[i].length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); instead of Background Color?

I am newbie in Android bitmap. How can I achieve it?

Community
  • 1
  • 1
komal sharma
  • 195
  • 1
  • 3
  • 12

0 Answers0