使用Linkify或Autolink后,TextView会被突出显示

3

我有一条长文本消息,后面跟了一个链接,并将其放入TextView中。就像这样:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content" android:layout_height="wrap_content">
    <LinearLayout android:orientation="vertical"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <TextView android:id="@+id/details" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:padding="10dp"
            android:text="@string/message" android:textSize="16sp" android:autoLink="web"/>
    </LinearLayout>![alt text][1]
</ScrollView>

当我选择链接时,整个文本都会被突出显示。如何防止这种情况发生?

只是为了澄清,我使用了linkify来做这件事,但它没有起作用。我甚至尝试设置一个自定义的正则表达式来解析文本的一部分,但也没有起作用。 - sazwqa
可能只是模拟器问题?你试过在真实设备上运行吗? - ShadowGod
是的,我试过了,发现这种情况也会出现在股票API演示中。奇怪的是,这种行为对我来说看起来很奇怪。肯定有解决方法,但我只是想知道我是否遗漏了什么。 - sazwqa
2
你能解决这个问题吗?我也遇到了同样的问题,正在寻找解决方案。 - Sheehan Alam
2个回答

0

不确定是否仍需要。这应该可以防止具有链接的TextView出现奇怪的高亮效果。您也应该能够在XML中设置这些。

textview.setCursorVisible(false);
textview.setFocusableInTouchMode(false);

0

包括 android:textColorHighlight 在内的任何内容都没有效果,但是

textView.setHighlightColor(Color.TRANSPARENT);

对我有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接