String url="注册宝驾会员代表您已同意《我们服务条款》,请认真阅读。"; SpannableStringBuilder style = new SpannableStringBuilder(url); TextViewURLSpan myURLSpan = new TextViewURLSpan(); style.setSpan(myURLSpan,12,20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tv_service.setText(style); tv_service.setMovementMethod(LinkMovementMethod.getInstance());
private class TextViewURLSpan extends ClickableSpan{ @Override public void updateDrawState(TextPaint ds) { ds.setColor(getResources().getColor(R.color.c_new_blue)); ds.setUnderlineText(false); //去掉下划线 } @Override public void onClick(View widget) {//点击事件 Intent intent=new Intent(getApplicationContext(),RegServiceA.class); startActivity(intent); } }
设置TextView中的部分位置可以点击,颜色不同
时间: 2024-11-10 12:26:13