我希望让用户修改应用中使用微调的语言(或任何方式)。 我尝试过很多方法,但他们改变这种活动的语言不是所有的活动,我要救它,以便当用户重新启动应用程序,他会发现最后选用的语言。
I want to let the user change the language of my application using spinner (or any way). I tried many ways but they change the language of this activity not all activities, and I want to save it so when the user restart the app he will find the last choosed language.
您可以使用此code的微调或任何你想要的
you can use this code in spinner or any way you want
String languageToLoad = "en"; // your language
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());
那么你应该保存语言像这样
then you should save the language like this
SharedPreferences languagepref = getSharedPreferences("language",MODE_PRIVATE);
SharedPreferences.Editor editor = languagepref.edit();
editor.putString("languageToLoad",languageToLoad );
editor.commit();
和从使用相同的code在每一个活动的onCreate()
加载 languageToLoad
共享preferences
and use the same code in every activity in onCreate()
to load the languageToLoad
from the SharedPreferences