开发者

TextView underline phone number and hyperlink

开发者 https://www.devze.com 2023-01-03 00:21 出处:网络
I\'ve written an app开发者_C百科 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?

I've written an app开发者_C百科 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?


<TextView 
   ...
   android:autoLink="all"
/>

That's actually enough for you


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:

  1. Mark up your text with HTML, particularly <u>...</u> for underlines
  2. Run that through Html.fromHtml() to get a Spannable with your formatting in place
  3. Feed that Spannable to your TextView via setText()

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消