I want to have few text as hyperlink in my TextView like the following image:

Also, similar to above Image I want the hyperlink to open the respective setting window. How is this possible?
EDIT: Just to make my question more specific, I want to open cellular setting when those text are clicked. So, I don't know what will be the URL for that to use href tag in String object.
Thanks in Advance!
Use SpannableString for this
SpannableString ss = new SpannableString("Your string value");
ClickableSpan clickableTerms = new ClickableSpan() {
@Override
public void onClick(View textView) {
// show toast here
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(true);
}
};
ss.setSpan(clickableTerms, 4, 10, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
myTextView.setText(ss);
myTextView.setMovementMethod(LinkMovementMethod.getInstance());
myTextView.setHighlightColor(Color.TRANSPARENT);
You can make multiple words clickable by this method.
Try this with the help of HTML anchor tag
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "No intenet connection. Make sure that <a href='any url'> Wi-Fi</a> or <a href='any url'> cellular mobile data is turned on</a>, then try again";
textView.setText(Html.fromHtml(text));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With