-1

I've create one layout with two image button. I want change language when button is pressed.

I've create res-values-it and res-values-en, now I can I do?

Ormet
  • 75
  • 12
  • 2
    Possible duplicate of [Change language programmatically in Android](http://stackoverflow.com/questions/2900023/change-language-programmatically-in-android) – OneCricketeer Feb 25 '17 at 17:08
  • http://stackoverflow.com/questions/40942535/using-locale-to-force-android-to-use-a-specific-strings-xml-file-for-a-non-suppo – Onik Feb 25 '17 at 17:09
  • config.locale = locale @Deprecated and I can't use it!! i don't know i can I do!! – Ormet Feb 25 '17 at 19:12
  • So? If you're under API level 24 use `config.locale = locale`. For API 24+ use `setLocales(LocaleList)` as per the [documentation](https://developer.android.com/reference/android/content/res/Configuration.html#locale) – Onik Feb 25 '17 at 19:49
  • I'm Api 21!! is deprecated! I'm using Eclipse.. – Ormet Feb 25 '17 at 21:52
  • 1
    :)) If you're on API 21, how come it's deprecated? :) – Onik Feb 25 '17 at 22:00
  • Sorry, I haved min sdk= 21 and api level 25. It's my fault! thaks! – Ormet Feb 26 '17 at 09:24
  • `if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { config.locale = locale; } else { // use API for 24+ }` – Onik Feb 26 '17 at 12:00

2 Answers2

1

i used this one for french

 String languageToLoad  = "fr_FR";
     Locale locale = new Locale(languageToLoad); 
     Locale.setDefault(locale);
     Configuration config = new Configuration();
     config.locale = locale;
     context.getResources().updateConfiguration(config,context.getResources().getDisplayMetrics());

Intent intent = new Intent(XYZ.this, XYZ.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Festim Dehar
  • 117
  • 2
  • 12
0

I think you have to add a settings Menu in wich user can select language that will be stored as a SharedPreference. then when displaying text you have to get language from SharedPreferences and use conditions to select text from res-values-it or res-values-en . i guess that should be usefull.

Boubakr Echieb
  • 127
  • 1
  • 17