Force Locale on Android






4.40/5 (4 votes)
While playing with localization on the Android for my app I came upon an annoying bug.It seems running on Motorola Milestone the fonts were getting smaller on each locale update.I use the following code for locale changing (from http://almondmendoza.com/2009/01/28/force-localize-an-application-
While playing with localization on the Android for my app I came upon an annoying bug. It seems running on Motorola Milestone the fonts were getting smaller on each locale update.
I use the following code for locale changing (from http://almondmendoza.com/2009/01/28/force-localize-an-application-on-android/):
String languageToLoad = "de"; Locale locale = new Locale(languageToLoad); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, null);
Also in the AndroidManifest.xml I have (without this entry you get "Something wrong here, didn't expect "mypackagename" to be resumed"):
<activity android:label="@string/app_name" android:name=".Dex" android:configChanges="locale">
Here is how my screen should look like:
And here is how it was looking on Motorola Milestone.
After changing the Locale from Preferences the fonts keep gettting smaller and smaller
This was very annoying. I did not know exactly why this was happening. So I decided to reproduce the Milestone in the emulator. I got the specifications of the Milestone from the web and created in Eclipse an AVD with a resolution of 480x854 and density of 240.
After that I was able to reproduce the bug. It seems the density was the issue here. I searched for Android density and after some tries I found the solution. It seems I needed to have this in the AndroidManifest.xml
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
The most important is the android:anyDensity =" true "
. After this, the application was shown correctly even on the Motorola Milestone.
I hope this will be of help and don't forget to check out my enhanced logcat tool here http://adrianvintu.com/blogengine/post/Colored-Logcat-Script-for-Windows.aspx
Edit: please read the comments of the article on my blog, you may find solutions to some of your localization problems - e.g. changing orientation resets locale, etc.
Edit 2: people have reported that sometimes the location resets to system default. Please read my post here: locale change does not affect menu