一下代码在同一个Textview里面设置了2段不同的文字和点击事件。
TextView protocalTv=(TextView)findViewById(R.id.protocal); String str=protocalTv.getText().toString(); SpannableString spannableString1 = new SpannableString(str); spannableString1.setSpan(new ClickableSpan(){ public void onClick(View widget) { com.caimao.gjs.utils.WebviewUtils.showRiskBook(OpenAccountThird.this) ;//风险揭示书 } }, str.length()-5, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString1.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_blue)), str.length() - 5, str.length(),Spannable.SPAN_EXCLUSIVE_INCLUSIVE); spannableString1.setSpan(new ClickableSpan(){ public void onClick(View widget) { com.caimao.gjs.utils.WebviewUtils.showRelevantAgreement(OpenAccountThird.this); //电子化相关协议 } }, 7,14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString1.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.color_blue)), 7, 14, Spannable.SPAN_EXCLUSIVE_INCLUSIVE); protocalTv.setText(spannableString1); protocalTv.setMovementMethod(LinkMovementMethod.getInstance());