How to force hyphenation in TextView? (character "-" on word split)
Asked Answered
P

1

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.

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?

Pachton answered 13/2, 2017 at 22:56 Comment(2)
developer.android.com/reference/android/widget/… is all that TextView itself offers, AFAIK.Tuchman
well, tryed with introTextView.setHyphenationFrequency(Layout.HYPHENATION_FREQUENCY_FULL); but not working at all. Same behaviourPachton
G
1

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.

Guest answered 24/4, 2023 at 9:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.