Hello. It is necessary in TextView to implement something like "Pressing the Pay button, you agree to the rules." Moreover, the word "rules" has a color different from the main text color of the TextView, and is clickable, that is, when you click on it, it switches to another activation. autoLink is not suitable, because there only certain text formats can be links, and the mechanism itself is not very suitable. I ask for your help.

  • there is already a solution on stackoverflow - pavel163
  • It uses autoLink, which, as I have said, does not fit, because I need to make custom text clickable, and not the phone number or site address. - Nikita
  • There they make a link clickable - pavel163

1 answer 1

You can implement exactly what you need:

SpannableString ss = new SpannableString("Нажимая кнопку Оплатить, Вы соглашаетесь с правилами"); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View textView) { startActivity(new Intent(MainActivity.this, AnotherActivity.class)); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; ss.setSpan(clickableSpan, 43, 52, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextView textView = (TextView) findViewById(R.id.myTV); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setHighlightColor(Color.TRANSPARENT); 

It will look like this:

enter image description here