How to change the language throughout the application program?

This code for some reason does not change the language in the application, it changes only in the current activity.

public void changeLanguageApp(){ SharedPrefHelper sharedPrefHelper=new SharedPrefHelper(context); Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { conf.setLocale(new Locale( sharedPrefHelper.getUserLanguage() )); // API 17+ only. } res.updateConfiguration(conf, dm); } 

How to make it so that when you click on a button, the application changes the language?

In my case, switching works only with a trace. start up

  • mb as context take getApplicationContext () - activation method - Sviat Volkov
  • LOOK. Change is changing. But the interface changes only when I restart the application again. And I want it to be like in the Standard Android. Tobish chose a language and the language has changed - Andro
  • PLEASE TELL ME. How to change the language to Arabic so that RTL also works. Tobish icons and badges turned upside down - Andro
  • in the layout, the views have left / right characteristics; change them to the same ones, but start \ end takes into account language features. Those. if Arabic is on, the button will turn over - Sviat Volkov

1 answer 1

Try to execute this code in the main Activity.

 Locale locale = new Locale(language_code.toLowerCase()); Locale.setDefault(locale); Configuration config = new Configuration(); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { config.setLocale(locale); createConfigurationContext(config); } else { config.locale = locale; getResources().updateConfiguration(config, null); } 
  • Thanks Artem. But I need to immediately change the language. And not after restarting the application - Andro