Android carriage return inside concatenated string
Android carriage return inside concatenated string
请快速提问。
我正在读取 NFC 标签并在我的设备屏幕上显示结果,它是这样显示的:
The content of the tag is : bla bla bla
我希望有 2 行显示如下:
The content of the tag is :
bla bla bla
我加了
android:singleLine="false"
在 TextView 定义中,但现在虽然我有 2 行,但它并没有在我希望的位置剪切,因为我得到了这个 :
The content of the tag is : bla
bla bla
周围很多人都在谈论 \n
和 \r
,但我不明白如何将它们集成到我的 textView 中,因为它是一个串联:
TextView.setText("The content of the tag is : " + result);
有什么建议吗?干杯
试试
TextView.setText("Tag is :\n" + result);
或必要时
TextView.setText("Tag is :\n" + result.replaceAll("[^\w]+", " "));
它只是将任何不是字母或数字的字符替换为 space。
请快速提问。
我正在读取 NFC 标签并在我的设备屏幕上显示结果,它是这样显示的:
The content of the tag is : bla bla bla
我希望有 2 行显示如下:
The content of the tag is :
bla bla bla
我加了
android:singleLine="false"
在 TextView 定义中,但现在虽然我有 2 行,但它并没有在我希望的位置剪切,因为我得到了这个 :
The content of the tag is : bla
bla bla
周围很多人都在谈论 \n
和 \r
,但我不明白如何将它们集成到我的 textView 中,因为它是一个串联:
TextView.setText("The content of the tag is : " + result);
有什么建议吗?干杯
试试
TextView.setText("Tag is :\n" + result);
或必要时
TextView.setText("Tag is :\n" + result.replaceAll("[^\w]+", " "));
它只是将任何不是字母或数字的字符替换为 space。