I want to make the string "this link" underlined and clickable, but I don't know how to achieve that.
XML file:
<string name="submitText">Before you submit, please check out <u>this link</u></string>
In my fragment:
tvSubmit.setText(Html.fromHtml(getString(R.string.submitText)));
I don't want the whole string to be clickable, only the underlined section. I cannot use a horizontal LinearLayout
with 2 cells, because on smaller devices the string won't have a continues look, it will be sectioned in 2 cells.
What have I tried:
tvSubmit.setMovementMethod(LinkMovementMethod.getInstance());
Spannable sp = (Spannable) tvSubmit.getText();
ClickableSpan click = new ClickableSpan() {
@Override
public void onClick(View widget) {
showLink();
}
};
sp.setSpan(click, 0, sp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
The code above makes the whole string underlined and also the color of the text is changed into light blue.