3

I am facing issue with setting in app locale to zh_HK. The code Locale locale=new Locale("zh_HK") also not working and upon printing locales.getAvailable locales list, I am getting zh_HK_#Hans,zh_HK_#Hant. Further more setting Locale locale=new Locale("zh_HK_#Hans") is also NOT working.

in the printed list of available locales it has no option like zh_HK. I am importing java.utils.Locale.

Zoe
  • 27,060
  • 21
  • 118
  • 148
mradss
  • 31
  • 3

2 Answers2

0

in your class that extands Application put this code :

public class myApp extends Application {
 @Override
    public void onCreate() {
        super.onCreate();
Locale locale = new Locale("zh","HK");
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getApplicationContext().getResources().updateConfiguration(config, null);
}
}
Yessine Mahdouani
  • 1,225
  • 12
  • 24
0

also you must set DisplayMetrics , in this way:

Locale myLocale = new Locale("zh","HK");
    Locale.setDefault(myLocale);
    Resources res = getApplicationContext().getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.setLayoutDirection(myLocale);
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
Milad Mohamadi
  • 127
  • 1
  • 10