0

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

Vishal Vasani
  • 647
  • 8
  • 16
Slava
  • 443
  • 4
  • 12

2 Answers2

0

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.

Mark
  • 86
  • 6
  • Yes, it takes default system language, but I want to implement language change in application – Slava Apr 21 '22 at 10:23
0

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)) }