8

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!

nikib3ro
  • 20,366
  • 24
  • 120
  • 181

4 Answers4

13

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"

Warpzit
  • 27,966
  • 19
  • 103
  • 155
  • Doesn't answer the question being asked. Question refers to non-link text in the TextView. `android:textColorLink` only affects the link text. – TalkLittle May 10 '14 at 20:50
  • @TalkLittle the question is how to avoid link color change. This does exactly that. You can combine it with textcolor for a specific color or simply use the standard text color as textColorLink. – Warpzit May 11 '14 at 04:30
  • Read the last sentence again. "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?" – TalkLittle May 11 '14 at 07:29
  • @TalkLittle Ah yes, I've must misread it when I answered it (2012). I'll update answer. – Warpzit May 11 '14 at 10:44
  • This works for email links as well `android:autoLink="email"` .. thanks! – Gene Bo May 12 '16 at 15:34
6

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);
Tom
  • 61
  • 1
  • 1
0

Tried changing any of these properties of your TextView ?

android:focusable - Boolean that controls whether a view can take focus. 

android:focusableInTouchMode - Boolean that controls whether a view can take focus while in touch mode. 

android:hapticFeedbackEnabled - Boolean that controls whether a view should have haptic feedback enabled for events such as long presses. 

android:clickable - Defines whether this view reacts to click events. 

I guess setting one of these to false would disable the visual feedback on the text elements.

Vidar Vestnes
  • 42,644
  • 28
  • 86
  • 100
-1

Guys, looks like a weird bug to me, but i found a solution, use HTML to give the text a shade of white:

text.append(Html.fromHtml("

That's it! With #FFFFFF it blinks, without, not. duh.

Martijn
  • 159
  • 1
  • 1
  • 6