【问题标题】:Odd selection behavior with LinkifyLinkify 的奇怪选择行为
【发布时间】:2011-05-26 14:17:04
【问题描述】:

我有一个 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>

【问题讨论】:

  • 我猜你可能为导致颜色变化的 TextView 控件定义了一个颜色状态列表。如果没有看到更多代码,就很难更精确。
  • 我没有定义任何颜色状态列表。只是一个普通的文本视图......
  • 那么请提供更多有关问题的上下文。包含此控件的 XML 布局的详细信息将是一个好的开始。
  • 使用 XML 布局更新问题

标签: java android url textview linkify


【解决方案1】:

添加:

android:textColor="#ffffff"

到 xml 中的 TextView 元素解决了问题......似乎覆盖 textcolor 覆盖了与元素相关的其他颜色样式......看到这个问题:Android text view color doesn't change when disabled

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-29
      • 2014-05-28
      • 2011-08-19
      • 2013-04-27
      • 2015-07-13
      • 1970-01-01
      • 2012-10-17
      • 1970-01-01
      相关资源
      最近更新 更多