I am trying to create a button that changes the app language.I created the string file for the language and I tried this code for changing the default language but with no success:
public void changeLang(Context context, String language) { Locale locale = new Locale(language); Locale.setDefault(locale); Configuration config = context.getResources().getConfiguration(); config.setLocale(locale); context.createConfigurationContext(config); context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics()); restartActivity();}private void restartActivity() { Intent intent = getIntent(); finish(); startActivity(intent);}
and this is how I called it:
changeLang(getApplicationContext(),"iw");
Thank you !