开发者

Odd selection behavior with Linkify

I have a TextView with some text that has URL's. I have used Linkify to turn them into clickable URL's:

    Linkify.addLinks(bodyTextView, Linkify.WEB_URLS);

However, when I click on text that is NOT a URL the text color changes. This also happens with the textview is set to AutoLink.

Here is my layout:

<?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" andr开发者_Go百科oid: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>


Adding:

android:textColor="#ffffff"

to TextView element in xml solves problem... it seems that overriding textcolor overrides other color styles related to element... see this question: Android text view color doesn't change when disabled


That is the default behaviour. You can set the text colour explicitly using the android:textColor attribute, but then you do not see any visual change to the link when it is clicked. One solution is to set android:textHighlightColor to match the normal text colour. The non-link text stays the same, and you see a visual cue when the link is clicked (the background of the link turns the colour of the rest of the text).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜