1

I have TextView which should accept max 6 characters. If value has more than 6, I want to show 3 dots at the end. Used these attributes to achieve that but it just simply cut text at the end without 3 dots.

 android:textAlignment="viewEnd"
 android:maxLines="1"
 android:maxLength="6"
 android:ellipsize="end"
martin1337
  • 2,384
  • 6
  • 38
  • 85
  • Does this answer your question? [Android, How to limit width of TextView (and add three dots at the end of text)?](https://stackoverflow.com/questions/10748796/android-how-to-limit-width-of-textview-and-add-three-dots-at-the-end-of-text) – Gowthaman M Oct 13 '22 at 08:46
  • 1
    If it's a spannabe text user CharSequence . it is a bug in ellipsize – Narendra_Nath Oct 13 '22 at 09:08

1 Answers1

2

Cleanest and quickest way would be to do so programatically as otherwise you'd need to do hard calculations of the text size + font alongside the TextView's width

This is the cheapest

textView.text = if(text.length > 6) text.take(6).append("…") else text
Some random IT boy
  • 7,569
  • 2
  • 21
  • 47