I am attempting to set an app-wide style for my TextViews that has a specific color for links. If I set android:textColorLink on each individual TextView, it works fine. However, if I set android:textColorLink inside a style in styles.xml, it continues displaying the normal android:textColor. Has anyone else experienced this or know of a solution? I would prefer to set it as the style so I do not need to update multiple references if the color were to change in the future.
The following method of individually setting android:textColorLink for each TextView does work and will display color1 for normal text and color2 for links.
styles.xml:
<style name="textStyle" parent="Widget.AppCompat.TextView">
<item name="android:textColor">@color/color1</item>
</style>
Layout file:
<TextView
android:textAppearance="@style/textStyle"
android:textColorLink="@color/color2" />
If I instead try just updating the style to include android:textColorLink instead of listing it on each TextView, it does not work and will display color1 for all normal text and links.
styles.xml:
<style name="textStyle" parent="Widget.AppCompat.TextView">
<item name="android:textColor">@color/color1</item>
<item name="android:textColorLink">@color/color2</item>
</style>
Layout file:
<TextView
android:textAppearance="@style/textStyle" />
A coworker helped me find the solution to this soon after posting. I had assumed that
android:textColorLinkwould be able to be set throughandroid:textAppearancesince I am already settingandroid:textColorthe same way. However, it would appear thatandroid:textColorLinkcan only be set throughstyle. I am not certain why there is this difference in the ways the colors are applied through styles. If anyone more knowledgeable knows why, please let me know.For example, this works.
styles.xml:Layout file:
This can also be cleaned up a bit so you only need to set
styleon the TextViews.styles.xml:Layout file: