Android - Add Margin for SpannableStringBuilder using ReplacementSpan

前端 未结 3 1361
面向向阳花
面向向阳花 2021-02-09 19:51

I\'m trying to format Hashtags inside a TextView/EditText (Say like Chips mentioned in the Material Design Specs). I\'m able to format the background using ReplacementSpan

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 20:11

    Doesnt BackgroundColorSpan work?

    For your specific case, you can also set the lineSpacing for the TextView.

    One last option (didn't test this), would be to calculate the height of the span to be larger than the one that you are drawing. You can check getSize implementation in DynamicDrawableSpan to see how to set the height of the span using the given FontMetrics instance as a parameter.

提交回复
热议问题