如果你想獲得本地化String不改變當前的配置(API> = 17):
Configuration config = new Configuration(context.getResources().getConfiguration());
config.setLocale(locale);
return context.createConfigurationContext(config).getText(resId);
其中locale
是您要測試的對象之一。
如果你的目標較低API級別:
Configuration conf = context.getResources().getConfiguration();
conf.locale = new Locale("de");
// Then update resources based on this Configuration.
context.getResources().updateConfiguration(conf, context.getResources().getDisplayMetrics());
// Afterwards, resources will retrieve localised strings instead of default locale
String deLocaleString = context.getResources().getString(R.string.my_string);
你就不能使用'context.getResources()的getString(R.string.wrongpass)'? – 2014-10-07 11:35:58