仅在TextView上加下划线在文本的第一行加底线

时间:2019-02-18 18:18:09

标签: android kotlin textview

我需要在具有多行的TextView中加下划线。我添加了油漆标记以在文本下划线:

textView.text = resources!!.getString(R.string.a_string)
textView.paintFlags = textView.paintFlags or Paint.UNDERLINE_TEXT_FLAG 

但是,它仅取消对第一行上的文本的轮廓,而不对第二行和后面的内容进行分界。此外,它只是随机地不适用于某些TextView,而不适用于其他TextView。有人可以解释一下是否有任何特殊的考虑因素,在某些情况下该方法可行,而在某些情况下却不可行?

这是我的TextView定义(ConstraintLayout):

<TextView
      android:id="@+id/title"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_marginStart="24dp"
      android:layout_marginTop="32dp"
      android:layout_marginEnd="32dp"
      android:text="Some text taht goes to more than one line."
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="0"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toBottomOf="@id/some_id"
      app:strokeColor="@color/black"
      android:lineSpacingExtra="8dp"
      />

1 个答案:

答案 0 :(得分:0)

好的,这很愚蠢,但是。 由于没有底部填充,因此第二行的下划线不可见。 我添加了android:paddingBottom="8dp",下划线变得可见。我不确定为什么必须首先添加它。

相关问题