I've written an app which contains a large textview for displaying notes. Is it possible to have the textview highlight any phone numbers or hyperlinks without underlining the entire view?
A:
You can use Linkify
to turn phone numbers, URLs, and such into links that, when clicked on, launch appropriate apps (Dialer, Browser, etc.).
If you were fishing for just an underline effect, without the links, you can:
- Mark up your text with HTML, particularly
<u>...</u>
for underlines - Run that through
Html.fromHtml()
to get aSpannable
with your formatting in place - Feed that
Spannable
to yourTextView
viasetText()
Here is the list of HTML tags supported by Android 2.1's edition of Html.fromHtml()
. Note that this is not officially documented anywhere, so your mileage may vary.
CommonsWare
2010-06-11 22:41:51
Thank you. I wasn't aware of that class. I'll look into that.
Chris
2010-06-14 19:59:37
+4
A:
<TextView
...
android:autoLink="all"
/>
That's actually enough for you
Fedor
2010-06-11 23:35:24
Yeah, I keep forgetting about this. `Linkify` is good if you need more control, or only want to apply a conversion to part of the text.
CommonsWare
2010-06-14 20:25:48