【问题标题】:Load default value of string programmatically [duplicate]以编程方式加载字符串的默认值[重复]
【发布时间】:2017-07-15 18:55:10
【问题描述】:

我的strings.xml 中有一个带有翻译的字符串:

default: <string name="help">Help</string>
values-de: <string name="help">Hilfe</string>
values-it: <string name="help">Aiuto</string>

假设我的设备是意大利语的。我的字符串看起来像

艾奥托

假设我在显示“Aiuto”的TextView 下方有一个Button

当我按下按钮时,我需要将字符串重置为默认值,所以在这种情况下是从

“Aiuto”到“帮助”

有什么方法可以通过编程方式做到这一点?

【问题讨论】:

标签: android localization


【解决方案1】:

您可以使用Locale.setDefault() 以编程方式设置区域设置。

请注意,区域设置将在配置更改时重置。 有关如何处理的信息,请参阅此帖子: Changing Locale within the app itself

【讨论】:

  • 感谢您的回答。我明白了,但我不需要更改整个应用程序区域设置。我只是一些字符串是英文的,而不是全部
  • @Daniele 那么这个答案肯定会对你有所帮助。 stackoverflow.com/a/9475663/3857465
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多