I have such code, and its work fine, but it change language only in context which was applied. I need to run this code in all activities. How can i change language in all app? I run this code in MainActivity.
Locale locale = new Locale(language);
Locale.setDefault(locale);
Resources resources = context.getResources();
Configuration configuration = resources.getConfiguration();
context.createConfigurationContext(configuration);
configuration.locale = locale;
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
return true;
I took this code from answer on question: Language not changing in app Android Studio
CodePudding user response:
I don't think there is an answer that would fit here because what you're asking is essentially supporting multiple languages for an app. I recommend searching youtube for tutorials or if you have no problem reading the official documentation then the the Android Developer website is probably you best bet.
CodePudding user response:
It's better if you have BaseActivity class and In that class override method attachBaseContext() which sends a Context object which can be used in the activity.
override fun attachBaseContext(newBase: Context) { super.attachBaseContext(LangContextWrapper.wrap(newBase, LangManager.currentLang)) }