Android中的不间断冒号

Android中的不间断冒号,android,scala,line-breaks,Android,Scala,Line Breaks,我有以下一行文字:地址:345346943693495349534963 我希望这条线总是这样断开(确切的断开点并不重要,但不应该是冒号): 在我的Android 4.2.2设备上,它会像上面那样崩溃,但在Android 6.0 emulator上,它的行为不同: address: 345346943693495349534963 如何使破坏行为在所有设备上保持一致 当我在画布上绘制文本时,会得到不同的结果,下面是代码(在Scala中): 您可以使用(\u00AD),必须将其放置在数字字符串的

我有以下一行文字:
地址:345346943693495349534963
我希望这条线总是这样断开(确切的断开点并不重要,但不应该是冒号):

在我的Android 4.2.2设备上,它会像上面那样崩溃,但在Android 6.0 emulator上,它的行为不同:

address:
345346943693495349534963
如何使破坏行为在所有设备上保持一致

当我在画布上绘制文本时,会得到不同的结果,下面是代码(在Scala中):

您可以使用(\u00AD),必须将其放置在数字字符串的多个点上:

address:3\u00AD453469\u00AD4369\u00AD349534953\u00AD4963
不幸的是,这将呈现连字符,我不知道这是否适合您:

address:3453469436934-
95349534963
这也适用于TextView的
android:text
属性

附言: 我还考虑过像这样使用Html:

Html.fromHtml("<span style="display: inline-block;">address:3</span>45346943693495349534963");
Html.fromHtml(“地址:345346943693495349534963”);

但不幸的是,我无法让它在Android中工作

看起来您正在寻找Joiner unicode代码点这个词

它也被称为零宽度无中断空间(ZWNBSP)

根据另一个问题:

从版本5(棒棒糖)开始,Android就应该支持它。这同样适用于软催眠(PhilLab回应中建议)

我建议你尝试一下,你可以把它写成
​。把它放在冒号和数字之间

如果在棒棒糖出现之前它不起作用,并且你需要支持以前的平台,那么我唯一能想到的就是测量文本,一个字符一个字符地测量,并且知道视图的可用宽度(你必须单独计算),在文本中手动添加一行你想要拆分的内容

通过阅读本文,您可以了解Android中文本度量的工作原理:


也许也有一种使用Spans的方法,但我不知道有任何方法。

感谢您接受答案,您选择了哪种解决方案?
    before draw a text on canvas follow following step and 

               String temp = "address:345346943693495349534963";
               String firstString=temp.substring(0, 21);
               [![enter image description here][1]][1]String secondString = temp.substring(20);
               String finalString = firstString+"\n"+secondString;

    now finally draw a text on canvas with "finalString",and if set text in textview then set final string in textview.

               TextView yourTextView = (TextView) findViewById(R.id.txt1);
               yourTextView.setText(finalString);


  [1]: http://i.stack.imgur.com/godJJ.png
Html.fromHtml("<span style="display: inline-block;">address:3</span>45346943693495349534963");
    before draw a text on canvas follow following step and 

               String temp = "address:345346943693495349534963";
               String firstString=temp.substring(0, 21);
               [![enter image description here][1]][1]String secondString = temp.substring(20);
               String finalString = firstString+"\n"+secondString;

    now finally draw a text on canvas with "finalString",and if set text in textview then set final string in textview.

               TextView yourTextView = (TextView) findViewById(R.id.txt1);
               yourTextView.setText(finalString);


  [1]: http://i.stack.imgur.com/godJJ.png