Android Build a Weather App Building the Weather UI The Legal Side of APIs

Ikuyasu Usui
Ikuyasu Usui
44,656 Points

How to remove underline for Powered by Dark Sky TextView?

I figured that textColorLink will change the color of the TextView caused by assigning a link but cannot figure out how to remove the underline that indicates the text has an anchor. Stackoverflows tells some ways but I don't know why it has to be such complicated for the seemingly easy task of writing a few tags to set the style.

3 Answers

Hi. May I ask why you would want to remove the underline? It is here to signal the user that there's a hyperlink attached to the text and clicking on it takes them to the website.

If you do not want to go with that, just remove the hyperlink from the string resource, make your Powered by Dark Sky TextView clickable and create an intent that opens up the given webpage into a browser.

Hope that helps :)

Ikuyasu Usui
Ikuyasu Usui
44,656 Points

That's a good alternative to the question although I would know that if I wasn't looking for seemingly quick trick to do that like text-decoration=none in CSS.

I see. Thanks for explaining. I'm not aware of anything similar in Android, no. Intents are usually used. But maybe someone else here does know a quick hack.

Ryan Dsouza
Ryan Dsouza
9,335 Points

It's really complex. I would use a simple markup in XML by using the style attribute. Not the best practice but for such a small request, using an entire method in main activity seems an overkill

But the notion of ensuring that the user know's its a link by seeking the underline is super valid.

Hi Ryan Dsouza. Would you mind sharing your xml-only solution here please? It would benefit everyone. Thank you :)

Ryan Dsouza
Ryan Dsouza
9,335 Points

Hi Lauren Moineau,

I was wrong about that approach. I assumed that android would give me privileges as I had for the normal XML file. I believe right now, that the only way to implement this request is using the following approach mentioned in this Link

Hi Ryan. Thank you for sharing. The tutorial you linked will remove the underline indeed but I'm afraid it would not work with this project as the android:autoLink="web" XML attribute and the URLSpan class only apply to a text containing a URL. It is not the case in this project as the text for the credits is "Powered by DarkSky". We could, of course, decide to write "Powered by www.darksky.net", in which case the solution you shared will be fine.

Another way to remove the underline for this project (on a text without URL) would be to use Linkify with a custom link String, using a RegEx pattern, but it definitely feels like a lot of work for such a small piece of text. I still believe a simple 3-line intent with a clickable textview would be quite a sensible solution in this case.

Ryan Dsouza
Ryan Dsouza
9,335 Points

Lauren Moineau Your solution makes a lot of sense. I was too obsessed with doing that modification in XML that I didn't think elsewhere.