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!
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.
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.
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"
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With