ClickableSpan

ClickableSpan is underlined by default, and text has a background color when clicked. You can get rid of that by overwriting updateDrawState.

 val clickableSpan = object : ClickableSpan(){
     override fun updateDrawState(ds : TextPaint){
         super.updateDrawState(ds)
         // Remove the underscore
         ds.isUnderlineText = false
         // Remove the background color of the text when clicked
          ds.bgColor = Color.parseColor("#FFFFFFFF")
           // Remove the default theme color of the font and change it to the color you want.
           ds.color = Color.parseColor("#ffacacac")}}Copy the code

ForegroundColorSpan

ForegroundColorSpan is set multiple times in a file, and only the last call takes effect. It can be solved by CharacterStyle.

  val colorSpan1 : ForegroundColorSpan
  val colorSpan2 : ForegroundColorSpan
  val builder : SpannableStringBuilder
  builder.setSpan(CharacterStyle.wrap(colorSpan1))
   builder.setSpan(CharacterStyle.wrap(colorSpan2))
Copy the code