var str = "点击同意即表示您已阅读并同意《一二三四用户注册协议》与《一二隐私政策》"
val ssb = SpannableStringBuilder()
ssb.append(str)
val start = str.indexOf("《")//第一个出现的位置
ssb.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
//用户协议
//跳转链接
}
@SuppressLint("ResourceAsColor")
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.color =context.resources.getColor(R.color.main_color_blue)
ds.isUnderlineText =false
}
}, start, start +15, 0)
ssb.setSpan(ForegroundColorSpan(Color.BLACK), 26, 27, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
val end = str.lastIndexOf("《")
ssb.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
//隐私政策
//跳转链接
}
@SuppressLint("ResourceAsColor")
override fun updateDrawState(ds: TextPaint) {
super.updateDrawState(ds)
ds.color =context.resources.getColor(R.color.main_color_blue)
ds.isUnderlineText =false
}
}, end, end +8, 0)
控件id.movementMethod = LinkMovementMethod.getInstance()
控件id.setText(ssb, TextView.BufferType.SPANNABLE)
网友评论