android隐私协议组件,Android 服务协议隐私政策高亮可点击写法
private fun setText() {//拼接字符串val spanBuilder = SpannableStringBuilder("同意")/*** 服务协议*/var span = SpannableString("服务协议")//服务协议点击事件span.setSpan(object : ClickableSpan() {override fun onClick(widget: V
private fun setText() {
//拼接字符串
val spanBuilder = SpannableStringBuilder("同意")
/**
* 服务协议
*/
var span = SpannableString("服务协议")
//服务协议点击事件
span.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
Toast.makeText(this@LoginActivity,"服务协议",Toast.LENGTH_SHORT).show()
}
}, 0, span.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
//设置颜色、下划线
span.setSpan(
ForegroundColorSpan(Color.parseColor("#D1894A")),
0,
span.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
spanBuilder.append(span)
spanBuilder.append("与")
/**
* 隐私政策
*/
span = SpannableString("隐私政策")
span.setSpan(object : ClickableSpan() {
override fun onClick(widget: View) {
Toast.makeText(this@LoginActivity,"隐私政策",Toast.LENGTH_SHORT).show()
}
}, 0, span.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
span.setSpan(
ForegroundColorSpan(Color.parseColor("#D1894A")),
0,
span.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
spanBuilder.append(span)
// 赋值给TextView
tv_service_agreement.movementMethod = LinkMovementMethod.getInstance()
tv_service_agreement.text = spanBuilder
//设置高亮颜色透明,因为点击会变色
tv_service_agreement.highlightColor = ContextCompat.getColor(applicationContext, R.color.transparent)
}
更多推荐
所有评论(0)