@@ -195,9 +195,14 @@ class NitroTextImpl(private val view: AppCompatTextView) {
195195 val end = builder.length
196196 if (start == end) continue
197197
198- frag.fontColor?.let { parseColorSafe(it)?.let { c ->
199- builder.setSpan(ForegroundColorSpan (c), start, end, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
200- }}
198+ // Apply font color for non-link fragments, or store for links to apply after URLSpan
199+ val hasLink = frag.linkUrl?.isNotEmpty() == true
200+ if (! hasLink) {
201+ frag.fontColor?.let { parseColorSafe(it)?.let { c ->
202+ builder.setSpan(ForegroundColorSpan (c), start, end, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
203+ }}
204+ }
205+
201206 frag.fragmentBackgroundColor?.let { parseColorSafe(it)?.let { c ->
202207 builder.setSpan(BackgroundColorSpan (c), start, end, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
203208 }}
@@ -224,11 +229,16 @@ class NitroTextImpl(private val view: AppCompatTextView) {
224229 if (url.isNotEmpty()) {
225230 builder.setSpan(UrlSpanNoUnderline (url), start, end, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
226231 hasLinks = true
227- // Apply default link color if fragment doesn't have explicit color
228- if (frag.fontColor == null ) {
229- // Use system link color (typically blue)
230- val linkColor = android.graphics.Color .parseColor(" #007AFF" )
231- builder.setSpan(ForegroundColorSpan (linkColor), start, end, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
232+ // Apply link color - use custom color if provided, otherwise use default
233+ // This must be applied AFTER the URLSpan to ensure it takes precedence
234+ val linkColor = if (frag.fontColor != null ) {
235+ parseColorSafe(frag.fontColor)
236+ } else {
237+ // Use system link color (typically blue) as default
238+ android.graphics.Color .parseColor(" #007AFF" )
239+ }
240+ linkColor?.let { c ->
241+ builder.setSpan(ForegroundColorSpan (c), start, end, Spannable .SPAN_EXCLUSIVE_EXCLUSIVE )
232242 }
233243 }
234244 }
0 commit comments