簡體   English   中英

如何更改 textview 超鏈接的顏色?

[英]how to change color of textview hyperlink?

我將此代碼用於超鏈接:

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/hyperlink" 
    android:text="@string/hyperlink"
    android:autoLink="web"/>

默認情況下它顯示藍色,但是如何更改 Android 中超鏈接的顏色?

android:textColorLink="yourcolorhere"添加到您的TextView

如果您想以編程方式更改它:

yourText.setLinkTextColor(Color.RED);

您可以在 XML 文件上使用:

android:textColorLink="Code" 

“代碼”可以是例如#ff0000或@color/red

您可以在 JAVA 代碼上使用:

tv.setLinkTextColor(color);

顏色可以是例如Color.REDColor.parseColor("#ff0000");

您需要使用android:textColorLink="#000000"其中000000是您的顏色的十六進制代碼。 希望能幫助到你。

您也可以打開 colors.xml 並將以下顏色更改為您想要的任何顏色:

<color name="colorAccent">#FF4081</color>

您需要使用android:textColorLink="colorCode" 希望它會奏效。

如果有人需要知道這個藍色的十六進制值,那就是#7bc9c2。

我使用滴管來解決這個問題,因為我在任何地方都找不到它,無論如何它不在谷歌調色板上:

https://www.google.com/design/spec/style/color.html#color-color-palette

TextView標簽的 xml 文件中:

android:autoLink="web" //link the content of web  
android:textColorLink="#FFFFFF" //change the color of the link 

將這些代碼行添加到textview文件中的XML中,它將正常工作

android:autoLink="web"
 android:textColorLink="@android:color/holo_orange_dark"
 android:linksClickable="true"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM