Set Locale programmatically

后端 未结 14 1662
Happy的楠姐
Happy的楠姐 2020-11-22 05:55

My app supports 3 (soon 4) languages. Since several locales are quite similar I\'d like to give the user the option to change locale in my application, for instance an Itali

14条回答
  •  爱一瞬间的悲伤
    2020-11-22 06:27

    simple and easy

    Locale locale = new Locale("en", "US");
    Resources res = getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.locale = locale;
    res.updateConfiguration(conf, dm);
    

    where "en" is language code and "US" is country code.

提交回复
热议问题