我已经写了一行:
String Mess = R.string.mess_1 ;
获取字符串值,但不是返回字符串,而是给我整数类型的 id。我怎样才能得到它的字符串值?我在 string.xml
文件中提到了字符串值。
最佳答案
试试这个
String mess = getResources().getString(R.string.mess_1);
更新
String string = getString(R.string.hello);
您可以使用 getString(int)
或 getText(int)
来检索字符串。 getText(int)
将保留应用于字符串的任何富文本样式。
引用:https://developer.android.com/guide/topics/resources/string-resource.html
关于android - 如何从 android 中的 string.xml 读取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2183962/