是否可以在运行时/或通过代码更改在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?

查看:454
本文介绍了是否可以在运行时/或通过代码更改在Android上res/strings.xml中添加的字符串的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以使用资源字符串来存储值,但是是否可以在运行时更改这些值?

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.

以下是使用SharedPreference的示例:

Here is a sample for using SharedPreference: How to use SharedPreferences in Android to store, fetch and edit values

这篇关于是否可以在运行时/或通过代码更改在Android上res/strings.xml中添加的字符串的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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