如何在 Android 上运行时生成 XML 资源? [英] How do I generate XML resources at runtime on Android?
本文介绍了如何在 Android 上运行时生成 XML 资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的资源文件夹中有不同的 strings.xml 文件(values、values_fr、values_de...),我想在运行时加载其他翻译.即使已经编译,是否可以将新字符串添加到这些文件中?或者有什么解决方法?
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?
推荐答案
简单的答案是你不能.您不能将硬编码的内容修改为 APK 资源.
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:
- 假设读取资源,对其进行修改,然后将其保存到另一个外部文件夹(SD 卡左右)
- 创建
AssetManager
在这些文件上 - 然后创建
Resources
以后可以作为普通的Android资源存储在APK中
这篇关于如何在 Android 上运行时生成 XML 资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文