7

I'm using a TextView extension class which writes a String like a typewriter, character per character. It works fine but when is writing a word which not fit in the current line, it makes a annoying behaviour and deletes the non fitting workd from the current line and writes it into the next line.

Welcome all. I need to know how to tell a TextView to use Hyphenation, it must force word breaks like this:

superlargewo-
rd

verylarg-
eword

It means putting character - instead of passing the word to the next line

How can that be force into TextView?

halfer
  • 19,824
  • 17
  • 99
  • 186
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • 3
    https://developer.android.com/reference/android/widget/TextView.html#attr_android:hyphenationFrequency is all that `TextView` itself offers, AFAIK. – CommonsWare Feb 13 '17 at 23:01
  • 1
    well, tryed with introTextView.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL); but not working at all. Same behaviour – NullPointerException Feb 14 '17 at 18:13

1 Answers1

0

For anyone looking how to make hyphen work quickly via xml, this worked for me under SDK 25+

Add hyphenationFrequency and hypen \u00AD into your String in xml layout like this.

before

android:text="Sylabe: "

after

 android:text="Sy\u00ADla\u00ADbe: "
 android:hyphenationFrequency="normal"

make sure nothing is set to limit lines of text

 android:singleLine="false"

It results in following text depending on space:

Sylabe

or

Sy-
labe 

or

Syla-
be

notes:
\u200B breaks text without any hyphen.

GreenMarty
  • 232
  • 3
  • 7