hanggrian/socialview

Differents Spans Doesn't Apply

Closed this issue · 3 comments

What I want to do is apply a span to a text that is going to show up inside a SocialTextView. For example:

Username_here Hello @Someone and good morning to @someone_else.

I want to make the "Username_here" part of the string be bold (which I can do via a Spannable) and the rest of the text (Hello @Someone and good morning to @someone_else) to behave like it should since it is a SocialTextView (meaning being able to handle clicks on mentions and links).

But the bold part is not showing bold is showing regular.

Any ideas what we can do to solve this issue?

As I was saying in #78, put this code in TextWatcher.

Matcher matcher = textView.getMentionPattern().matcher(spannable);
while (matcher.find()) {
    int start = matcher.start();
    int end = matcher.end();
    StyleSpan span = new StyleSpan(android.graphics.Typeface.BOLD);
    spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

Thank you for answering me ! I just did it by my own means though ! You can close this issue.

Bro, ini saya sudah pakai seperti ini tapi kok tetap tidak BOLD ya? kenapa ya bro?

textView.addTextChangedListener(object : TextWatcher {
    override fun afterTextChanged(value: Editable?) {
        val spannable = SpannableString(value)
        val matcher: Matcher = textView.mentionPattern.matcher(spannable)
        while (matcher.find()) {
            val start: Int = matcher.start()
            val end: Int = matcher.end()
            spannable.setSpan(StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
        }
    }
    override fun beforeTextChanged(value: CharSequence?, p1: Int, p2: Int, p3: Int) {}
    override fun onTextChanged(value: CharSequence?, p1: Int, p2: Int, p3: Int) {}
})