问题描述
因此,在strings.xml中,我有一个名为change_bg的字符串,我想根据点击事件更改其值.
So inside strings.xml I have a string called change_bg and I'd like to change it's value according to click events.
我知道,为了获得价值,您可以使用
I know that in order to get the value you use
changeBG=getString(R.string.change_bg);
但是我不知道如何设置 R.string.change_bg
But I don't know how to SET the value ofR.string.change_bg
请让我知道如何.
提前谢谢!Dvir
推荐答案
您无法在运行时更改资源文件.字符串是 string.xml
文件中的硬编码
,因此在运行时无法更改.如果您要尝试的是使用 SharedPreferences
来存储用户的首选项,而不是尝试编辑您的 strings.xml
文件.
You can't change resource files during runtime. Strings are hard-coded
in the string.xml
file and hence can't be changed during runtime. Instead of trying to edit your strings.xml
file, just use SharedPreferences
to store the user's preferences if that's what you're trying.
这篇关于Android-更改strings.xml中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!