如何从android中的string.xml读取值? [英] how to read value from string.xml in android?

查看:25
本文介绍了如何从android中的string.xml读取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一行:

String Mess = R.string.mess_1 ;

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

to get string value, but instead of returning string, it is giving me id of type integer. How can I get its string value? I mentioned the string value in the string.xml file.

推荐答案

试试这个

String mess = getResources().getString(R.string.mess_1);

更新

String string = getString(R.string.hello);

您可以使用 getString(int)getText(int) 来检索字符串.getText(int) 将保留应用于字符串的任何富文本样式.

You can use either getString(int) or getText(int) to retrieve a string. getText(int) will retain any rich text styling applied to the string.

参考:https://developer.android.com/guide/主题/资源/字符串资源.html

这篇关于如何从android中的string.xml读取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆