Reputation: 4199
I am using this code for hyperlink:
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/hyperlink"
android:text="@string/hyperlink"
android:autoLink="web"/>
By default it is showing blue color, but how do I change color of hyperlink in Android?
Upvotes: 334
Views: 112951
Reputation: 11110
My Compose hyperlink changed color
val annotatedString = buildAnnotatedString {
withStyle(style = SpanStyle(color = Color.Red)) { // your color
append("Link Text")
addStringAnnotation(
tag = "URL",
annotation = "https://www.example.com",
start = 0,
end = "Link Text".length
)
}
}
ClickableText(
text = annotatedString,
onClick = { offset ->
annotatedString.getStringAnnotations(tag = "URL", start = offset, end = offset)
.firstOrNull()?.let { annotation ->
// link click action code }
}
)
Upvotes: 0
Reputation: 1
You can also change the link color in your theme using android:textColorLink. You probably need to set both light and dark theme when you do that
Upvotes: 0
Reputation: 171
Add these Lines of code to your textview
in XML
file and it will work perfectly fine
android:autoLink="web"
android:textColorLink="@android:color/holo_orange_dark"
android:linksClickable="true"
Upvotes: 17
Reputation: 3629
In xml file of TextView
tag :
android:autoLink="web" //link the content of web
android:textColorLink="#FFFFFF" //change the color of the link
Upvotes: 2
Reputation: 1951
You can use on your XML file:
android:textColorLink="Code"
the "Code" can be e.g. #ff0000
or @color/red
You can use on your JAVA code :
tv.setLinkTextColor(color);
The color can be e.g Color.RED
or Color.parseColor("#ff0000");
Upvotes: 22
Reputation: 1615
You need to use the android:textColorLink="#000000"
where 000000
is your color's hex code. Hope it helps.
Upvotes: 14
Reputation: 51
You need to use android:textColorLink="colorCode"
. Hope it will work.
Upvotes: 3
Reputation: 12031
You can also open colors.xml and change the following color to whatever you want:
<color name="colorAccent">#FF4081</color>
Upvotes: 5
Reputation: 293
If anyone needs to know the hex value for this blue it is #7bc9c2.
I used Eye Dropper to figure this out as I couldn't find it documented anywhere, it isn't on the Google Color Palatte anyway:
https://www.google.com/design/spec/style/color.html#color-color-palette
Upvotes: 4
Reputation: 3052
If you want to change it programmatically:
yourText.setLinkTextColor(Color.RED);
Upvotes: 55