Android TextView文字点击事件
本文目的:使读者快速使用(代码复制即可用)
SpannableString ss = new SpannableString(tip);
ss.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
//do what you want
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(getResources().getColor(R.color.green_23cc77));//文字颜色
ds.setUnderlineText(false);//不要下划线(默认有下划线)
}
}, startIndex, endIndex, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
TextView continueTip = (TextView) view.findViewById(R.id.tv_tip);
continueTip.setText(ss);
continueTip.setMovementMethod(LinkMovementMethod.getInstance()); //设置了这个点击才能生效