gpt4 book ai didi

android - 我可以从不同语言环境的 android 访问资源吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:13 25 4
gpt4 key购买 nike

我的应用程序中有两个语言环境。我可以在不更改当前语言环境的情况下访问资源,例如来自不同语言环境的字符串数组吗?我的意思是编码我不喜欢在设置中更改它。

最佳答案

更好的解决方案是(如果您使用的是 API 17):

@NonNull
protected String getEnglishString() {
Configuration configuration = getEnglishConfiguration();

return getContext().createConfigurationContext(configuration).getResources().getString(message);
}

@NonNull
private Configuration getEnglishConfiguration() {
Configuration configuration = new Configuration(getContext().getResources().getConfiguration());
configuration.setLocale(new Locale("en"));
return configuration;
}

关于android - 我可以从不同语言环境的 android 访问资源吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10874589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com