1、简介

问题描述:
1、用户协议和隐私政策高亮
2、点击用户协议和隐私政策调整到详细页面
废话不多说,直接上代码
这里我上核心代码,解决上门的问题
TextView mTvAgreement = custom.findViewById(R.id.agreementTv);
//将TextView的显示文字设置为SpannableString
mTvAgreement.setText(getClickableSpan());
//设置该句使文本的超连接起作用
mTvAgreement.setMovementMethod(LinkMovementMethod.getInstance());
//设置超链接文字
private SpannableString getClickableSpan() {
SpannableString spanStr = new SpannableString(mContext.getString(R.string.user_agreement2));
//设置文字的单击事件
spanStr.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
//点击高亮文本点击事件
BaseWebViewActivity.open((Activity) mContext,"http://xxx/html/myAgreement.html","用户协议和隐私政策");
}
@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.setUnderlineText(false);
}
}, 18, 31, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//18和31是高亮的启始和结束的下标
//设置文字的前景色
spanStr.setSpan(new ForegroundColorSpan(Color.RED), 18, 31, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//设置下划线文字
// spanStr.setSpan(new UnderlineSpan(), 18, 31, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spanStr;
}
网友评论