Is there a way to hide text in a TextView?

前端 未结 7 2435
清歌不尽
清歌不尽 2021-02-08 13:09

Is there a way to hide some (but not all) of the text in a TextView? I tried setting the size to 0 with AbsoluteSizeSpan, but that doesn\'t have any visual effect that I see.

7条回答
  •  一个人的身影
    2021-02-08 13:36

    I've figured out a way. Let's use SpannableString and Color.TRANSPARENT

    For example: <> Original text : "Hello dude"

    <> Expected text : "_____ dude"

    • Here i will use Kotlin:

    val spannableString = SpannableString("Hello dude")

    spannableString.setSpan(ForegroundColorSpan(Color.TRANSPARENT), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)

    yourTextView.text = spannableString

提交回复
热议问题