例如,我在 xml 中有一些字符串
<string name="String1">My String 1</string>
<string name="String2">My string 2</string>
我想在 Activity 中展示类似My String 1: My string 2
是否可以向同一个TextView添加多个
<TextView android:text="@string/String1"/>
<TextView android:text=": "/>
<TextView android:text="@string/String2"/>
问题在于,如果将它们插入 TableLayout 中,它们将被视为单元格,并且“:”符号不会写在 String1 旁边(它写在两个字符串的中间)。
是否可以在 xml 代码中仅在一个 TextView 中连接字符串(无需在 Java 中以编程方式进行)? 我的意思是有没有任何语法可以附加字符串之类的东西
<TextView android:text="@string/String1+:+@string/String2"/>
谢谢
最佳答案
你不能直接在 xml 中做,这是你能做的最好的:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string>
Resources res = getResources();
String text = String.format(res.getString(R.string.welcome_messages), username, mailCount);
关于android - 向 TextView 添加多个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4207068/