Android - Linkify,autoLink在触摸时删除文本颜色更改

时间:2010-03-25 21:20:52

标签: android

假设我在TextView中有以下文字:

Hey there, visit www.example.com

如果我设置TextView的属性autoLink =“all”,将正确检测www.example.com。但是,如果我现在触摸TextView,TextView的文本不是链接('嘿那里,访问'部分)将变灰。有没有办法防止这种行为?

谢谢!

4 个答案:

答案 0 :(得分:11)

在xml中,您只需执行以下操作:

使用以下内容设置文字颜色:

android:textColor="@color/yourcolor"

为链接设置颜色:

android:textColorLink="@color/yourcolor"

答案 1 :(得分:5)

如果你可以用代码而不是XML来实现它,下面的技巧对我有用,即使它有点多余。您基本上将文本颜色设置为现在的颜色。它不像其他人所说的那样“白”;它是一片灰色。无论颜色如何,都可以获得并重新设置。

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);

答案 2 :(得分:0)

尝试更改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. 

我想将其中一个设置为false会禁用文本元素的视觉反馈。

答案 3 :(得分:-1)

伙计们,对我来说看起来像一个奇怪的错误,但我找到了一个解决方案,使用HTML为文本提供了一个白色的阴影:

text.append(Html.fromHtml(“

就是这样! #FFFFFF闪烁,没有,没有。咄。