0

I have long German texts in Textview sth like "ProduktGruppen". I would like to add hyphen automatically in the middle if the size of the widget doesnot fit. So the end result would be

 "Produkt-
Gruppen"

I tried this with using Produkt\u00ADGruppen but I get no hyphen in android just breaking. I have seen also this lib https://github.com/bluejamesbond/TextJustify-Android but it is based in a custom widget?

Is there any best practice for hyphenation within languages like German?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
aselims
  • 1,843
  • 1
  • 17
  • 19

2 Answers2

0

Is that what you want ?

String s = "ProduktGruppen"; // your text
String[] r = s.split("(?=\\p{Upper})");  // Your string is split on the capitals
String res = r[0] + "-" + r[1];  // Add the string back together
Luca Ziegler
  • 3,236
  • 1
  • 22
  • 39
  • Not based on capitals.. the origin text is "Produktgruppen" and based on the width of the widget... if the width of the widget is smaller than the length of the word, hyphenate. if not keep it as it. – aselims Nov 20 '15 at 11:58
0

Allow me to refresh the argument. In the meantime browsers do hyphenate, and all we’d need is similar activity by Android’s browser. Hyphenation is even more important on small "smart" phone screens than on "Cinemascope"-size PC screens. Please have a look at https://www.typolexikon.de/, hyphenated on, for example, Firefox, and then compare to Android. Take "Seitenflächenkante" at https://www.typolexikon.de/vorbreite-nachbreite/. Grüße, Fritz@Joern.com