https://www.cnblogs.com/didikee/p/7851260.html
这是我的 kotlin实现
val linkWord1 = "<用户协议>"
val linkWord2 = "<隐私说明>"
val word = "登录表示同意XXXX${linkWord1}及$linkWord2"
val spannableStringBuilder = SpannableStringBuilder(word)
val index1 = word.indexOf(linkWord1)
val index2 = word.indexOf(linkWord2)
spannableStringBuilder.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
showXieyiDialog(userXieyiUrl ?: "")
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.setColor(Color.parseColor("#444444")) //设置文件颜色
ds.setUnderlineText(false) //设置下划线
}
}, index1, index1 + linkWord1.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
spannableStringBuilder.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
showXieyiDialog(privateXieyiUrl ?: "")
}
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.setColor(Color.parseColor("#444444")) //设置文件颜色
ds.setUnderlineText(false) //设置下划线
}
}, index2, index2 + linkWord2.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
login_xieyi.setText(spannableStringBuilder)
login_xieyi.setMovementMethod(LinkMovementMethod.getInstance())
网友评论