2

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

What do you mean exactly by "raching this class"? I am aware that i can't modify the res folder itself. I just want to change the behaviour of string getting instead. Subclassing every view in xmls seems tiresome.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.