Geki
Geki

Reputation: 247

Override string.xml with my own strings

i am trying to override all automatically parsed strings out of the strings.xml, so that android does use my strings instead of the ones in the strings.xml without changing the syntax in the xml files.

I want to use strings downloaded at runtime and display them in native TextViews, Buttons, ToolBars, etc. My first idea was to define a custom LayoutInflater.Factory and setting texts, hints and so on programatically after the view has been inflated. The problem is that the LayoutInflater code expects me to inflate the views myself and copy&pasting inflation logic seems like a bad idea.

My second idea was to wrap the AttributeSet and inject my own strings but i couldn't find a way to do that.

Does anyone has a viable, robust way to accomplish what i am trying?

Upvotes: 2

Views: 573

Answers (1)

koksalb
koksalb

Reputation: 431

When you provide a data as a Resource, it can't be modified during run time. To be precise, the "res" folder can't be modified with java codes.

This also applies to Strings.xml also, i.e "Values" folder.

The best thing you can do is to create a class of strings and feed the textviewss etc with those. You can reach this class and change the values in the code and refresh the layouts(reinflate) to change the outlooking.

Upvotes: 3

Related Questions