我有一项活动,用户可以更改应用的颜色重音。
选择的颜色保存在SharedPreferences
内。
我希望能够通过应用colors.xml
中保存的内容更改该内容,而不是在应用SharedPreferences
文件中包含静态值。
<color name="colorAccent">#value_from_shared_preferences</color>
我知道还有其他不同的方法可以将用户指定的颜色用作应用强调颜色,但我想知道如何在应用colors.xml
文件中切换出值。
更新:所有资源值都是常量,因此无法在运行时更改xml文件中的值。
参考: Programmatically change the value of a color resource obtained from API response