Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Linkify, autoLink remove text color change on touch

Tags:

android

Let's say I have following text in TextView:

Hey there, visit www.example.com

If I set TextView's attribute autoLink="all" www.example.com will be properly detected. However, if I now touch TextView, TextView's text that's not link ('Hey there, visit' part) will go gray. Is there a way to prevent this behavior?

Thanks!

like image 606
nikib3ro Avatar asked Mar 25 '10 21:03

nikib3ro


People also ask

What is Linkify in android?

android.text.util.Linkify. Linkify take a piece of text and a regular expression and turns all of the regex matches in the text into clickable links. This is particularly useful for matching things like email addresses, web URLs, etc. and making them actionable.

What is autoLink in android?

andorid:autoLink => By using this attribute, android can controls whether links(such as urls, emails, phone and address) are automatically found and converted to clickable links.


2 Answers

In xml you can simply do following:

Set color for text with:

android:textColor="@color/yourcolor"

Set color for links with:

android:textColorLink="@color/yourcolor"

like image 90
Warpzit Avatar answered Sep 21 '22 04:09

Warpzit


If you can get away with doing it in code instead of XML, the trick below worked for me even though it's kind of redundant. You're basically setting the text color to what it is now. It's not necessarily "white" as others have said; it's a shade of gray. Regardless of the color, this gets it and sets it again.

final TextView message = new TextView(TheApp.this);  
final SpannableString s = new SpannableString("Some text with example.com in it.");
message.setText(s);  
...
message.setTextColor(message.getTextColors().getDefaultColor());
...
Linkify.addLinks(message, Linkify.WEB_URLS);
like image 37
Tom Avatar answered Sep 22 '22 04:09

Tom