Android Linkify链接textColor被忽略,css样式覆盖可能吗?

CQM*_*CQM 8 android overriding textcolor textview linkify

Linkify在我的应用程序中使用,访问过的链接文本显示为深紫色.我的整体布局背景颜色为深蓝色,因此无法阅读.文本设置为白色,但访问过的链接显示为深紫色.我该如何覆盖它?

<TextView android:text="Website:" 
          android:layout_width="match_parent" 
          android:layout_height="wrap_content"
          android:textSize="14dip"
          android:paddingBottom="2dip"
          android:background="#ffffff"
          android:textColor="#577dbe" />              
<TextView android:text="http://www.mysite.com/"
          android:layout_width="match_parent" 
          android:layout_height="wrap_content"
          android:textSize="12dip"
          android:paddingBottom="6dip"
          android:textColor="#ffffff"
          android:id="@+id/contactWeb1" />  
Run Code Online (Sandbox Code Playgroud)

She*_*tib 18

事实证明这是一个简单的解决方案!

但是你将无法进行visited/ not visited区分.

    TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1);
    noteView.setText("http://www.blablaasd.com/");
    noteView.setLinkTextColor(Color.red); //for example
    Linkify.addLinks(noteView, Linkify.ALL);
Run Code Online (Sandbox Code Playgroud)

试图赶上访问过的州:

使用

    noteView.setLinkTextColor(getResources().getColorStateList(R.color.colors));
Run Code Online (Sandbox Code Playgroud)

代替

    noteView.setLinkTextColor(Color.red);
Run Code Online (Sandbox Code Playgroud)

res/创建文件夹color,并创建colors.xmlres/color/

colors.xml

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

    </item>
    <item
      android:state_window_focused="true" android:color="#00ff00">

    </item>
    <item android:color="#FF00ff"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

我尽力赶上访问过的州.我尝试了选择器可以采用的所有状态.

我可能错过了如果你发现了,分享(:


替代解决方案(仅适用于html链接)

以编程方式设置字体颜色

缺点(这一点要小心)

  • 您将不得不捕获它是否被访问(这是可行的)

    这意味着您没有覆盖访问过的链接功能.

代码:

TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1);
String desc = "<font color=\"red\"><a href='http://www.mysite.com/'>Visit my site</a></font>";
contactWeb1.setText(Html.fromHtml(desc));
contactWeb1.setMovementMethod(LinkMovementMethod.getInstance());
Run Code Online (Sandbox Code Playgroud)