Android:如何用字符包裹文字?(不是用言语)帮助我



这就是应用的外观。


我刚开始

研究Android。


,但我想要这个。


我刚开始

udying android。


我搜索了答案。这是搜索结果。


这有点骇客,但是您可以用Unicode no-Break Space角色(U 00A0)替换空格。这将导致您的文本被视为单个字符串,并包裹在字符上而不是单词上。

mystring.replace("," u00a0");


我应该在哪里放置该代码????

如果您不想替换代码中的字符串,而目的只是将void chan chan chan to nbsp,

您可以使用AAC的@BindingAdapter功能。

@BindingAdapter(“app:text”)
fun TextView.setText(str : String){
    this.text = str.replace(“ “,”u00A0”)
}

在xml中,

<TextView
    ...
    app:text=“Put your text here”
/>

快速方法是将所有空格替换为xml文件中的 u00a0

<TextView
...
app:text=“Put&#160;your&#160;text&#160;here”
/>

&amp;#160;(没有空间)是 u00a0在html unicode excape语法(https://unicode-table.com/en/00a0/)

>

或通过代码设置时

String myString="put your text here";
textView.setText(myString.replace(" ", "u00A0"));

最新更新