问题
I have an android TextView which has a link in it. The link looks fine and performs the correct action when the user taps on it, but while the user's finger is down the link doesn't change color at all. Is that normal Android behavior? Seems like a highlight or indicator of some kind would be helpful, especially if I have small text and a bunch of links next to each other. Is this what other people are seeing, is there an easy fix for this?
Also the slash on the end of the URL isn't part of the link. Smells like a bug in their RegEx.
Here's the code I'm using:
textView.setAutoLinkMask(Linkify.WEB_URLS);
textView.setText("Hi welcome to http://www.plopfizz.com/ please enjoy.");
回答1:
You could create an item selector with diff states, for example...
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:color="#FEFEFE" /> <!-- highlight -->
<item android:state_focused="true" android:color="#000000" />
<item android:color="#FFFFFF" /> <!-- default -->
</selector>
And then in your layout...
<TextView
...
android:textColor="@color/above_selector"/>
来源:https://stackoverflow.com/questions/12047300/android-textview-links-dont-highlight-when-clicked