Android TextView links don't highlight when clicked

ε祈祈猫儿з 提交于 2020-01-14 12:42:54

问题


I have an android TextView which has a link in it. The link looks fine and performs the correct action when the user taps on it, but while the user's finger is down the link doesn't change color at all. Is that normal Android behavior? Seems like a highlight or indicator of some kind would be helpful, especially if I have small text and a bunch of links next to each other. Is this what other people are seeing, is there an easy fix for this?

Also the slash on the end of the URL isn't part of the link. Smells like a bug in their RegEx.

Here's the code I'm using:

    textView.setAutoLinkMask(Linkify.WEB_URLS);
    textView.setText("Hi welcome to http://www.plopfizz.com/ please enjoy.");

回答1:


You could create an item selector with diff states, for example...

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="#FEFEFE" /> <!-- highlight -->
    <item android:state_focused="true" android:color="#000000" />
    <item android:color="#FFFFFF" /> <!-- default -->
</selector>

And then in your layout...

<TextView 
  ...
  android:textColor="@color/above_selector"/>


来源:https://stackoverflow.com/questions/12047300/android-textview-links-dont-highlight-when-clicked

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!