saket / Better-Link-Movement-Method

Attempts to improve how clickable links are detected, highlighted and handled in TextView
Apache License 2.0
780 stars 78 forks source link

How to remove underline and change color of span? #4

Closed sandeshlasnapure closed 7 years ago

saket commented 7 years ago

The library doesn't add any underline span to links. Can you please add a screenshot? The highlight color can be changed by using android:textColorHighlight="@color/your_color" on your TextView. If you're trying to change the color on all TextViews across your app, you can add a textViewStyle in your theme.

sandeshlasnapure commented 7 years ago

Thanks, did that and removed underline.

SureshSc commented 5 years ago

@saket @sandeshlasnapure I am getting underline, attaching screen shot

here is my code <TextView android:id="@+id/tvComments" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="@dimen/value_2" android:textColor="@color/medium_black" android:textSize="@dimen/value_sp_17" android:textColorHighlight="@color/transparent" android:lineSpacingExtra="2dp" />

screen shot 2019-02-14 at 11 06 24 am
saket commented 5 years ago

I think that's the default styling used by TextView. You'll have to manually replace those spans if you want.

val text: Spannable = ...

val urlSpans: Array<URLSpan> = text.getSpans(0, text.length, URLSpan::class.java)
for (urlSpan in urlSpans) {
  val startIndex = text.getSpanStart(urlSpan)
  val endIndex = text.getSpanEnd(urlSpan)
  text.removeSpan(urlSpan)
  text.setSpan(CustomUrlSpan(), startIndex, endIndex, 0)
}
SureshSc commented 5 years ago

@saket didnt work out, URLSpan count is 0

saket commented 5 years ago

That's not possible. You should check your data flow to ensure you're getting the right text.

saket commented 5 years ago

Actually, pass Any (or Object in Java) as the span type to debug what spans are present in your text.

text.getSpans(0, text.length, Any::class.java)
SureshSc commented 5 years ago

That's not possible. You should check your data flow to ensure you're getting the right text.

I am sure.

saket commented 5 years ago

URLs are only rendered when URLSpans are present in the text. If you're seeing linkified text then it means that there are URLSpans present in the text. It's contradictory otherwise.