How do I generate XML resources at runtime on Android?

别等时光非礼了梦想. 提交于 2019-12-28 05:45:16

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/4591696/how-do-i-generate-xml-resources-at-runtime-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!