EDIT:
I may be wrong in my understanding, but this is a different question than Set Locale programmatically since I already implemented the answer suggested there and I still have some issues.
In this questions I am asking for help in resolving that issues (issues that have no reference in the Set Locale programatically question).
Original post
I am trying to implement custom locale in my application and run into several issues.
I am using the below code in all my activities just before the call to setContentView:
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = new Locale(newLocale);;
res.updateConfiguration(conf, dm);
EDIT:
I also tested it with:
Resources res = getBaseContext().getResources();
I added to all activities in AndroidManifest.xml the below attribute:
android:configChanges="locale|orientation"
When the user select a new Locale I also run the above code to update the configuration.
The issues that I run into are:
- After changing the Locale only updated text in the current activity uses the new Locale (also when I press "back" in the previous activity only refreshed text uses the new Locale (If I start a new activity it uses the new Locale as expected).
- I use DataUtils to format dates, but it seems that whatever I do it ignores the new Locale.
- Same issue with DataPicker, I could not get it to use the new Locale.
- I could not make the new Locale effect my app widget.
For the first issue I solved it by applying the change only when the application start, and when the user update the Locale I show a message requesting the user to restart the application for the change to take effect. I prefer to make the change without restarting the application, but could not figure out how to make it work properly.
The second issue can be resolved if I use SimpleDateFormat with the custom Locale, however I prefer to use DateUtils if possible.
For the last two issues I could not find any way to overcome it.
Any help is appreciated.