1

I got the setLocale method for Android from this thread Change languages in app via strings.xml. The problem is that Android Studio says that locale is deprecated, And updateConfiguration(android.content.res.Configuration.androidtil.DisplayMetcis) is deprecated.

Does anyone know the work around?

/*- Set locale ------------------------------------------------------------ */
public void setLocale(String lang) {
    Locale 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(this, SignUp.class);
    startActivity(refresh);
}
Solo
  • 569
  • 1
  • 7
  • 27

1 Answers1

0

Resources.updateConfiguration is now deprecated, avoid directly changing the conf.locale field. From API 24 use:

conf.setLocale(locale);
PIXP
  • 2,382
  • 3
  • 19
  • 28