neworld / spanner

Simple and fluent spannable builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Click without underline support

neworld opened this issue · comments

spanner.append("google", url("http://www.google.lt"), noUnderline())

overriding the updateDrawState () in ClickableSpan, you can simply remove the underline.

code like this:

class ClickSpanBuilder(private val clickListener: OnClickListener) : SpanBuilder {

    override fun build(): Any {
        return EasyClickableSpan(this.clickListener)
    }

    private class EasyClickableSpan(private val clickListener: OnClickListener) : ClickableSpan() {

        override fun onClick(widget: View) {
            this.clickListener.onClick(widget)
        }

        override fun updateDrawState(ds: TextPaint) {
            super.updateDrawState(ds)

            // it's key to remove underline
            ds.isUnderlineText = false
        }
    }
}

If it is url, just inherit URLSpan and then the same as the above way.