在我的一个 Android 应用程序中,有一次我需要加载特定语言的字符串。例如:
values: <string name="txt_help">Help</string>
values-de: <string name="txt_help">Hilfe</string>
values-fr: <string name="txt_help">Aider</string>
现在我需要默认(值)文本。
有没有办法用给定的语言“en”加载键“txt_help”?我找不到可以将语言环境设置为附加参数的方法。
或者我可以用给定的语言环境创建一个新的 ResourceManager 并通过这个资源对象读取字符串吗?
提前非常感谢。 hjw
最佳答案
查看 the documentation ,这看起来很有希望:
Resources standardResources = context.getResources();
AssetManager assets = standardResources.getAssets();
DisplayMetrics metrics = standardResources.getDisplayMetrics();
Configuration config = new Configuration(standardResources.getConfiguration());
config.locale = Locale.US;
Resources defaultResources = new Resources(assets, metrics, config);
换句话说,创建一个配置为标准语言环境的新资源对象。
关于android - 从资源中加载语言特定的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244889/