如何从超链接中删除突出显示颜色[Android]

时间:2016-12-01 04:22:17

标签: android textview autolink

我想在用户点击textview时删除突出显示颜色。因此,我可以更改所有颜色并使其成功,但是当我单击textview时它不会打开链接。如果我删除AutoLink它的工作......

所以我的问题是如何在不使用自动链接的情况下删除突出显示?

XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@color/light_gray"
        android:state_pressed="true"/>
</selector>

背景可绘制:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
        android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
        android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>

颜色

String webTv1 = "<a href='http://www.google.com'> Customer Service </a>";
    tv1 = (TextView) findViewById(R.id.tv1);
    tv1.setClickable(true);
    tv1.setText(Html.fromHtml(webTv1));
    //set user name in blue color and remove underline from the textview
    Spannable spannedTv1 = Spannable.Factory.getInstance().newSpannable(
            Html.fromHtml(webTv1));
    Spannable processedText = removeUnderlines(spannedTv1);
    if (tv1 != null) {
        tv1.setText(processedText);
        tv1.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

public static Spannable removeUnderlines(Spannable p_Text) {
    URLSpan[] spans = p_Text.getSpans(0, p_Text.length(), URLSpan.class);
    for (URLSpan span : spans) {
        int start = p_Text.getSpanStart(span);
        int end = p_Text.getSpanEnd(span);
        p_Text.removeSpan(span);
        span = new URLSpanNoUnderline(span.getURL());
        p_Text.setSpan(span, start, end, 0);
    }
    return p_Text;
}

爪哇:

This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery

1 个答案:

答案 0 :(得分:5)

最后,我设法删除了高亮显示:

添加另一种颜色/ highlight.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#00ffffff"/>
</selector>

然后,在xml文件中定义颜色:

android:textColorHighlight="@color/hightlight.xml"

在此之前,从XML文件中删除autoLink ...