是否可以在运行时/或通过代码更改在Android上res/strings.xml中添加的字符串的值? [英] Is it possible to change the value of a string added in res/strings.xml on Android at run time/ or by code?
问题描述
我知道我们可以使用资源字符串来存储值,但是是否可以在运行时更改这些值?
I know we can use resource strings to store values, but is it possible to change those values at run time?
例如,我添加了两个新的资源元素用户名和密码,并且我想在运行时更改这些值.还是有替代的方法来存储值?
For example, I added two new resource elements username and password, and I want to change these values at run time. Or is there an alternate way to store values?
推荐答案
字符串资源是绝对静态定义的;您无法更改其值.使用SharedPreference
来存储您的数据,您可以更改,更新或做任何适合您需要的事情.
String resources are absolutely static defined; you can't change their values. Use SharedPreference
which is to store your data, and you can change, update or do whatever to suit your needs.
Here is a sample for using SharedPreference
: How to use SharedPreferences in Android to store, fetch and edit values
这篇关于是否可以在运行时/或通过代码更改在Android上res/strings.xml中添加的字符串的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!