Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing locale: Force activity to reload resources?

So I have a language setting in my application. When the language is switched, I would like all the textviews etc to change language immediately. Currently I just change the locale in the configuration, so the language has changed when the user restarts the activity.

An ugly solution to my problem would be to make each textview load the new resources each time the language is changed. Is there a better solution? Perhaps a neat way to discretely restart the activity? Or maybe just force reload of the resources?

like image 510
pgsandstrom Avatar asked Apr 15 '10 10:04

pgsandstrom


People also ask

How do you refresh a page on Android?

To refresh the browser on your Android device, launch Chrome and tap the three vertical dots at the top right corner of the screen to open the menu. Tap the “⟳” icon from the top menu and wait for the browser to reload the webpage.


2 Answers

In your AndroidManifest.xml, add this attribute to your Activity

android:configChanges="locale" 

In your activity override onConfigurationChanged()

@Override public void onConfigurationChanged(Configuration newConfig) {   // refresh your views here   super.onConfigurationChanged(newConfig); } 

https://developer.android.com/guide/topics/manifest/activity-element.html#config

like image 193
Jim Blackler Avatar answered Oct 12 '22 15:10

Jim Blackler


I think the question is switching language in runtime for the app and displaying localized messages in UI. android:configChanges="locale" calls onConfigurationChanged if the system locale is changed (in setting of your device) while the app is running, and not if you change locale in the code for your app, which I guess is what you want to accomplish. That's why it's not refreshing.

like image 38
MSquare Avatar answered Oct 12 '22 13:10

MSquare