Hello! I have an activity and 2 buttons in it. 1 Russian, 2 Kazakh language. Clicking the buttons should open another activity with the selected language. My Activity opens, but the language does not change.

I searched in Google, I did not find anything like it.

  • In my opinion, in the android language will be selected in accordance with what is used in your device. Try changing the language and clicking again. - koks_rs
  • No, I need to change the language of the application. For example, I clicked on the Russian language, the Russian interface opens, I clicked on the Kazakh language, the Kazakh interface opens - Andrei

3 answers 3

That's how I change the language in my application

 public void setLocale(String lang) { myLocale = new Locale(lang); Resources res = getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = myLocale; res.updateConfiguration(conf, dm); Intent refresh = new Intent(getActivity(), MainActivity.class); startActivity(refresh); } 

After changing the locale, you need to restart the activity

    Programmatically change the language in the android is not recommended.

      Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = new Locale(language_code.toLowerCase()); // вроде бы kk_KZ для казахстана res.updateConfiguration(conf, dm); 

      In the Activity code you need to register:

       @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Configuration configuration = getResources().getConfiguration(); configuration.locale = new Locale("ru"); getResources().updateConfiguration(configuration, getResources().getDisplayMetrics()); // для применения смены локали к заголовку setTitle(R.string.activity_title); // далее создаем layout } 

      So in each separate activit you can use your own language. But this is not recommended.

      • This is where to register? In every activity? - Andrei
      • @Andrei yes, in every activity in which you want to use a language other than the system language. And the language is set by the parameter в new Locale("ru"); . In this case, it is Russian. - lllyct
      • Helped, but there is something. Headings do not change when choosing a language - Andrei
      • Call obviously setTitle after changing the locale - lllyct