Green Ho
Green Ho

Reputation: 901

Android - Hyperlink missing underline

I use linkify to make a textview work as hyperlink, and it does work nicely. The only issue is the underline is missing, could anyone point me out what could cause the problem? shouldn't the underline come by default?

Thanks!

Upvotes: 0

Views: 538

Answers (2)

Ram Iyer
Ram Iyer

Reputation: 1679

You can use the xml attribute autoLink="web" for the TextView widget to automatically detect if the content is a web address. Here is an example:

<TextView
    android:id="@+id/text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:textColorLink="@color/hyperlink_blue"
    android:autoLink="web"
    android:textSize="16sp"/>

The attribute textColor is for text other than hyperlinks, which will be 'black' in the above example and the attribute textColorLink is for any text that takes a form of a hyperlink - which will be blue per above.

You can also append other autoLink values by 'piping' them together:

android:autoLink="web|email|map|phone"

This works for TextView, AppCompatTextView (SupportV7/AppCompat), AppCompatTextView (androidx/AppCompat)

Upvotes: 0

wtsang02
wtsang02

Reputation: 18873

Take a look at the Spannable params

addLinks(Spannable text,...)

linkify class

SpannableStringBuilder class

-replying to comment- SpannableStringbuilder implements CharSequence, which can be used in TextView.setText(); So once you finish making your underlined text, you can use TextView.setText() and still use the method your are using.

Or refer to this: How to set underline text on textview?

Upvotes: 2

Related Questions