开发者

Android - Linkify, autoLink remove text color change on touch

Let's say I have following text in TextView:

Hey there, visit www.example.com

If I set TextView's attribute au开发者_JS百科toLink="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!


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜