实现SpannableString的点击事件以及颜色设置ClickableSpan代码:
ClickableSpan clickableSpan = new ClickableSpan() {@Overridepublic void onClick (View widget) {startActivity( new Intent (SpecialLineCompanyListActivity. this, SpecialLineCreateCompanyActivity. class )) ;//响应点击事件}@Overridepublic void updateDrawState (TextPaint ds) {ds.setColor(getResources().getColor(R.color. colorTextBlue )) ;//设置颜色ds.setUnderlineText( false ) ;//去掉下划线}} ;SpannableStringBuilder builder = new SpannableStringBuilder() ;builder.append( " 暂无 \' " ) ;builder.append( title ) ;builder.append( " \' 相关信息,您可以发布该公司信息 \r " ) ;builder.append( " 为您推荐与 \' " ) ;builder.append( title ) ;builder.append( " \' 相关的其他公司 " ) ;builder.setSpan(clickableSpan, 12+title.length(),19+title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);//设置clickableSpantvDescribe .setText(builder) ;tvDescribe.setMovementMethod(LinkMovementMethod.getInstance());//必须设置才能响应点击事件