首页 > 解决方案 > Android TextView, lineSpacingExtra + backgroundColor 问题

问题描述

我正在使用带有 SpannableString 的 TextView 来更改某些单词的背景颜色,如下图所示,但 attr 'lineSpacingExtra' 存在问题。如您所见,使用“lineSpacingExtra”时添加了一些底部填充。我想知道如何使这个填充适合文本的高度。

这是我的代码片段。

在.kt

spannableString.setSpan(BackgroundColorSpan({color}), 0, text.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

在此处输入图像描述

在 .xml 中

<TextView
        android:id="@+id/tv_content"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="6dp"/>

我该如何解决这个问题?谢谢。

标签: androidspannablestring

解决方案


推荐阅读