URLSpan用于设置点击链接事件,点击相应文字可以跳转到特定链接。
需要配置 mTxHintView.movementMethod = LinkMovementMethod.getInstance()
参考代码如下:
var spannerString = SpannableString("登陆即代表您已阅读并同意用户协议及隐私政策")
val xieyiURLSpan = URLSpan("https://www.jianshu.com/p/")
val yinsiURLSpan = URLSpan("https://www.jianshu.com/p/")
spannerString.setSpan(xieyiURLSpan, 12, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
spannerString.setSpan(yinsiURLSpan, 17, 21, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
mTxHintView.text = spannerString
mTxHintView.movementMethod = LinkMovementMethod.getInstance()
网友评论