2

I want to change the default colour of 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());
Loren
  • 320
  • 1
  • 10
  • 25

1 Answers1

0

If you want to change the textcolor of the entire TextView just call textView.setTextColor(R.color.text_color).

If you want to colorize only parts of the TextView´s text:

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);

Note: Use String-Resources, do not pass a raw string ("By continuing,I agree to HCP User Agreement and Terms of Services " --> change to something like getString(R.string.accept_user_agreement))

sschmid
  • 1,341
  • 1
  • 16
  • 22