2011-05-26 88 views
1

我有一个带有URL的文本的TextView。我已经使用Linkify把它们变成可点击的网址:Linkify的奇怪选择行为

Linkify.addLinks(bodyTextView, Linkify.WEB_URLS); 

然而,当我点击文字是不是一个URL文本颜色的变化。这也发生在textview设置为AutoLink的情况下。

这里是我的布局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RelativeLayout 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:id="@+id/headerLinearLay" 
    android:orientation="horizontal" android:padding="4px"> 
    <ImageView 
     android:id="@+id/avatarImageView" 
     android:layout_height="48px" android:layout_width="48px"></ImageView> 
    <TextView 
     android:id="@+id/usernameTextView" 
     android:text="TextView" 
     android:paddingLeft="4dp" 
     android:layout_toRightOf="@id/avatarImageView" 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content"></TextView> 
</RelativeLayout> 
    <TextView android:text="TextView" android:layout_height="wrap_content" android:id="@+id/bodyTextView" android:textSize="24sp" android:layout_width="fill_parent" android:autoLink="web"></TextView> 
    <TextView android:text="TextView" android:layout_height="wrap_content" android:id="@+id/dateTextView" android:layout_width="fill_parent" android:layout_weight="1"></TextView> 
    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/toolbarLinearLayout" android:background="@color/solid_yellow" android:padding="5dip"> 
    <Button android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:id="@+id/replyButton" android:text="Reply"></Button> 
    <Button android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="RT" android:id="@+id/rtButton"></Button> 
    <Button android:id="@+id/dmButton" android:layout_width="fill_parent" android:layout_weight="1" android:layout_height="wrap_content" android:text="DM"></Button> 
</LinearLayout> 




</LinearLayout> 
+0

我想,也许你有一个颜色状态列表定义为导致颜色变化的TextView控件。没有看到更多的代码,就很难做到更精确。 – 2011-05-26 14:46:42

+0

我没有定义任何颜色状态列表。只是一个普通的文本视图... – 2011-05-26 14:52:19

+0

然后请提供一些更多的问题上下文。包含此控件的XML布局的详细信息将是一个好的开始。 – 2011-05-26 14:56:10

回答

0

这是默认行为。您可以使用android:textColor属性显式设置文本颜色,但是当点击链接时,您看不到链接的任何视觉变化。一个解决方案是设置android:textHighlightColor以匹配正常的文本颜色。非链接文本保持不变,当链接被点击时(链接的背景变成文本其余部分的颜色),您会看到一个视觉提示。