
I want to make the line "this link" underlined and clickable, but I do not know how to achieve it.
XML file:
<string name="submitText">Before you submit, please check out <u>this link</u></string>
In my snippet:
tvSubmit.setText(Html.fromHtml(getString(R.string.submitText)));
I do not want the entire line to be clicked, but only the underlined section. I canβt use a horizontal LinearLayout with 2 cells, because on smaller devices the line will not continue to look, it will be divided into 2 cells.
What 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);
In the above code, an entire line is underlined, and the text color changes to blue.
android textview hyperlink underline
Zbarcea christian
source share