我想更改link (textview)的默认颜色。
SpannableString ss = new SpannableString("By continuing,I agree to HCP User Agreement and Terms of Services ");
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
startActivity(new Intent(UserRegister.this, ForgotPassword.class));
}
};
ss.setSpan(clickableSpan, 48, 65, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView textView = (TextView) findViewById(R.id.termsAndConditions);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
如果你想改变整个TextView
的textcolor,只需调用textView.setTextColor(R.color.text_color)
。
如果您只想为TextView
的部分文本上色:
final SpannableStringBuilder stringBuilder = new SpannableStringBuilder("your-string");
final int start = 0, end = textView.getText().length(); // Change to the start/end of the part to colorize
// Apply some text-color
stringBuilder.setSpan(new ForegroundColorSpan(getResources()
.getColor(R.color.text_color)), start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
// Apply changes to TextView
textView.setText(stringBuilder);
注意:使用字符串资源,不要传递原始字符串("By continuing,I agree to HCP User Agreement and Terms of Services "
->更改为getString(R.string.accept_user_agreement)
)