7

I have a checkbox that has this text: "I agree to the terms and conditions". I need "terms and conditions" to be blue, underlined, and open a webpage when touched.

I did find the Linkify class (http://developer.android.com/reference/android/text/util/Linkify.html), but this seems to turn URLs already in text into to links.

How can I do this?

Neil Goodman
  • 1,276
  • 2
  • 16
  • 21

2 Answers2

15

Just use the string like

"I agree to the <a href="...">terms and conditions</a>"

and set movement method:

mCheckBoxTermsOfUse = (TextView) findViewById(R.id.checkBoxTermsOfUse);
mCheckBoxTermsOfUse.setMovementMethod(LinkMovementMethod.getInstance());

See api demos for details

JustAnotherCoder
  • 621
  • 7
  • 13
  • If I add the function `setMovementMethod()`, I do not see the text immediately, but only after I clicked once. Is there a solution? – offset Nov 18 '14 at 10:23
3

Color the text blue and add an onClick Listener to it that launches the intent to view the URL. You can markup your text using HTML like syntax via Html.fromHtml(). See this answer for better explanation and example.

Community
  • 1
  • 1
Andrew White
  • 52,720
  • 19
  • 113
  • 137