Linkify的奇怪选择行为

时间:2011-05-26 14:17:04

标签: java android url textview linkify

我有一个TextView,其中包含一些带有URL的文本。我使用Linkify将它们转换为可点击的URL:

    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>

2 个答案:

答案 0 :(得分:1)

添加:

android:textColor="#ffffff"

到xml中的T​​extView元素解决问题...似乎覆盖textcolor会覆盖与元素相关的其他颜色样式...请参阅此问题:Android text view color doesn't change when disabled

答案 1 :(得分:0)

这是默认行为。您可以使用android:textColor属性显式设置文本颜色,但是在单击链接时您看不到链接的任何可视更改。一种解决方案是设置android:textHighlightColor以匹配普通文本颜色。非链接文本保持不变,并且在单击链接时会看到视觉提示(链接的背景将转换文本其余部分的颜色)。

相关问题