As part of internationalizing an Android application I have come across the need to dynamically word wrap or hyphenate at the right position.
All my strings are exte
Soft hyphen worked on a Samsung Galaxy device starting with Android 4.3.
<!-- key combination to enter soft hyphen: [Alt Gr]+[-] or [Alt]+240 on German PC, see https://de.wikipedia.org/wiki/Weiches_Trennzeichen#Darstellung_auf_Computersystemen -->
<string name="no_connection">Nicht ver-bund-en</string>
Since my use case was pretty narrow, I just used one soft hyphen in the word "verbunden". The Unicode \u00ad had no effect.
Its a new thing from Android 6 Marshmellow.
Try adding this to your TextView xml
android:hyphenationFrequency="none"
Management of line breaks can be a hassle. The best option is to use UTF line-break modifier control characters since android supports full UTF
I know someone mentioned "soft-hyphen", but there are quite a few more.
You can also use the "Zero Width Space" between words on languages that lack spaces so you don't have to rely on dictionary interpretation. You can also use this as a soft-hyphen in languages that allow breaking of certain words over lines at certain points.
When using a compound word that you don't want broken, but you want the Text To Speech system to recognize it properly you should use "Word Separator" character. Don't use "Zero Width Non Breaking Space" as that has been deprecated due to it's use as BOM.
Finally, if you want a space but don't want a line break, use a simple non-breaking space.
The question is old but just found best solution for me:
I have to say i'm programming in Xamarin, so the code is in C# but should not be a problem to port into java.
I used the NHyphenator Logic (https://github.com/alkozko/NHyphenator) for Inserting SoftHyphens(UTF8 Symbol - 0x00AD) so the Textview do hyphenation at the right place.
To get Hyphenation for other languages i used the openoffice Dictionaries. e.g. i had to get Hyphenation for german-swiss language
http://extensions.openoffice.org/en/search?f[0]=field_project_tags%3A157 1. Download the extension 2. Unzip it with winrar or something else 3. Copy the hyph_xx_xx/hyph_xx_xx.dic file 4. Add new Language to the Hyphenator class
NHyphernator resource files are declared as: hyph-xx-xx.pat.txt --> content of the dic file without comments hyph-xx-xx.hyp.txt --> file which contains word-exceptions where the logic for hyphening does not give correct results
If anyone wants the portable Library for Xamarin just tell, i can upload it.
EDIT:
The breakstrategy should be set to Balanced in TExtview. API Level > 23, else don't use breakstrategy.
EDIT:
Here's the mono/xamarin code: https://github.com/sma84/NHyphenator-Mono
setEllipsize might be of help, if this error is yet fixed.
The following library supports hyphenation. It does all types of text alignment (left/right/center/justified) and hyphenation for you. Not all languages have been added but can be added as necessary. This library uses NO WEBVIEWS and SUPPORTS SPANNABLES and allows for LONG TEXT.
LIBRARY: https://github.com/bluejamesbond/TextJustify-Android
ANDROID: 2.2 to 5.X
SETUP
DocumentView documentView = addDocumentView(new StringBuilder("Your long text content"), DocumentView.PLAIN_TEXT);
documentView.getDocumentLayoutParams().setTextAlignment(TextAlignment.JUSTIFIED);
documentView.getDocumentLayoutParams().setHyphenator(new Hyphenator(HyphenPattern.PT));
documentView.getDocumentLayoutParams().setHyphenated(true);