So, as per a separate question that I asked I’m using the following code to switch languages.
When I change the language in Android manually (in settings) it pulls from the correct drawable and string resources, so I believe I have those configured correctly.
However when I call this code, nothing happens (literally, there’s no feedback of any kind, no error, no nothing).
I am not sure if I’m using the correct locale codes and am somewhat confused as to how locale translates to language… I’m hoping someone can tell me what specifically I’m missing here.
Resources res = getApplicationContext().getResources();
Locale locale = new Locale("us"); //here I have tried "en", "es", "en_US", "es_ES", nothing happens
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
res.updateConfiguration(config, res.getDisplayMetrics());
This is being called by means of a radio button toggle, and I have set the debugger and am sure that the code is being called and that it is passing the values I expect to the Locale.setDefault method.
All help greatly appreciated.
AH!
So, the solution (at least the one that works, if it’s not the right way perhaps someone else will chime in with what is the right way) appears to be to setContentView again AFTER this code. The language elements all display correctly then. And it is “en” for english and “es” for spanish.