Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Change value in strings.xml

Tags:

android

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);

But I don't know how to SET the value of R.string.change_bg

Please let me know how.

Thanks in advance! Dvir

like image 973
david Avatar asked May 19 '13 07:05

david


People also ask

How to write special characters in string XML in Android?

The reference to entity "Drop" must end with the ';' delimiter. How can I write character & in the strings. xml? In android studio, you can simply press Alt+Enter and it will convert for you.

What is the use of strings XML file in Android?

A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.

Why should you use string resources instead of hard coded strings in your apps?

Strings don't clutter up your application code, leaving it clear and easy to maintain.


1 Answers

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.

like image 82
Karthik Balakrishnan Avatar answered Oct 20 '22 02:10

Karthik Balakrishnan