You just use one SpannableString
and use the onClick
class ClickableSpan
. In this case I created a subclass, in case you want to create a link in more than one word. Ex:
public class MainActivity extends Activity {
TextView textView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
SpannableString ss = new SpannableString("Dispositivo de entrada dotado de um a três botões...");
//aqui você coloca o índice da palavra que você quer, no caso 0 até 11
ss.setSpan(new CustomClickableSpan(), 0, 11, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(ss);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
class CustomClickableSpan extends ClickableSpan {
@Override
public void onClick(View textView) {
// aqui você abre a Activity que você quer
// Intent....
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(Color.BLUE);//cor do texto
ds.setUnderlineText(false); //remove sublinhado
}
}
}
Documentation: Clickablespan, Spannablestring
Man, that’s exactly what I was looking for. Thank you so much for your help.
– Daybson