Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate XML resources at runtime on Android?

I have different strings.xml files in my resources folders (values, values_fr, values_de...), and I would like to load additional translations during runtime. Is it possible to add the new strings to those files even if it has already been compiled? Or is there a workaround?

like image 871
Hrk Avatar asked Jan 04 '11 08:01

Hrk


People also ask

How does XML work in Android?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.

How do I manage resources in Android?

Resource Manager is a tool window for importing, creating, managing, and using resources in your app. You can open the tool window by selecting View > Tool Windows > Resource Manager from the menu bar or by selecting Resource Manager on the left side bar. Click Add to add a new resource to your project.


1 Answers

The simple answer is that you can't. You can't modify hard-coded stuff into APK resources.

But there are some options. For instance you can:

  • Let's say read a resource, modify it, and save it into another external folder (SD card or so)
  • Create AssetManager over those file(s)
  • Then create Resources which can be later used as ordinary Android resource stored in APK
like image 136
Barmaley Avatar answered Nov 08 '22 18:11

Barmaley