SpannableStringBuilder builder = new SpannableStringBuilder("同意《XXX用户服务协议》");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View widget) {
mKeyBoardViewDialog.show();
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setUnderlineText(false);//设置点击文字的下划线是否存在
}
};
builder.setSpan(clickableSpan, 2, builder.length(),
Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
builder.setSpan(new ForegroundColorSpan(Color.BLUE), 2, builder.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mTvProtocol.setText(builder);
mTvProtocol.setMovementMethod(LinkMovementMethod.getInstance());// 设置点击时需要加上这种模式,不然的话没有效果
mTvProtocol.setHighlightColor(Color.TRANSPARENT);//设置点击后的背景颜色为透明
SpannableStringBuilder的使用
最新推荐文章于 2022-11-20 21:27:40 发布