OGeek|极客世界-中国程序员成长平台

标题: android - 如何从 android 中的 string.xml 读取值? [打印本页]

作者: 菜鸟教程小白    时间: 2022-8-1 01:20
标题: android - 如何从 android 中的 string.xml 读取值?

我写了一行:

String Mess = R.string.mess_1 ;

获取字符串值,但不是返回字符串,而是给我整数类型的 id。我怎样才能得到它的字符串值?我在 string.xml 中提到了字符串值文件。



Best Answer-推荐答案


尝试这个

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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4