2011-08-03 54 views
5

有關我的Android應用程序在頁面上顯示的超鏈接我這樣做:如何更改超鏈接的顏色在android系統

MyProgram.java

link1.setText(Html.fromHtml(linkText1)); 
     link1.setMovementMethod(LinkMovementMethod.getInstance()); 


     TextView link = (TextView) findViewById(R.id.textView2); 
     String linkText = "Visit the <a href='http://www.mydomain.com'>My Website</a> web page."; 
     link.setText(Html.fromHtml(linkText)); 
     link.setMovementMethod(LinkMovementMethod.getInstance()); 
     // Place email address 
     TextView email = (TextView) findViewById(R.id.textView3); 
     String emailText = "Contact Me: <a href=\"mailto:[email protected]\">[email protected]</a>"; 
     email.setText(Html.fromHtml(emailText)); 
     email.setMovementMethod(LinkMovementMethod.getInstance()); 

myprogram.XML

<TextView android:text="TextView" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="30dp"></TextView> 
     <View 
     android:layout_width="fill_parent" 
     android:layout_height="30dp"> 
    </View> 
     <TextView android:text="TextView" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="30dp"></TextView> 

如果你看到我的XML,我試圖改變顏色爲黑色(android:textColor =「#000000」),但我仍然沒有e超鏈接中的任何更改。它仍然是默認顏色,即藍色

任何幫助?

回答

23

您應該使用其他屬性:

android:textColorLink="#000000" 
+0

感謝它的工作 – super

1

檢查這個代碼:

String text = "Visit stackoverflow.com"; 
    TextView label = new TextView(this); 
    label.setText(text); 
    Pattern pattern = Pattern.compile("stackoverflow.com"); 
    Linkify.addLinks(label, pattern, "http://"); 
    label.setLinkTextColor(Color.CYAN);