Changing locale programmatically not working in some devices

后端 未结 2 1438
-上瘾入骨i
-上瘾入骨i 2020-12-17 22:26

I\'ve the following piece of code:

/**
 * Sets a new Locale for the APP.
 * @param newLocale - Valid new locale.
 */
private static void setLocale( String ne         


        
相关标签:
2条回答
  • 2020-12-17 22:34

    Well,

    User Sir SC provided an answer which worked. But my code, also worked. The issue we were facing, was about a single device ignoring this locale change. So AFAIK, it's just a single device, and it might be caused because of a buggy ROM, as it was a Genymotion Emulator.

    So overall, the answer is:

    • The code OP posted, is valid and working. So is the code from Sir SC.

    Cheers.

    0 讨论(0)
  • 2020-12-17 22:46

    This is the code I am using for localisation. It is used by + 1m people and never heard of any complaint about not changing strings so I hope it will work for you as well:

    On top of class:

    Locale myLocale;
    

    Function:

        public void setLocale(String lang) { 
            myLocale = new Locale(lang); 
            Resources res = getResources(); 
            DisplayMetrics dm = res.getDisplayMetrics(); 
            Configuration conf = res.getConfiguration(); 
            conf.locale = myLocale; 
            res.updateConfiguration(conf, dm);
            reloadUI(); // you may not need this, in my activity ui must be refreshed immediately so it has a function like this.
        }
    

    Function Call:

    //example for setting English
    setLocale("en_gb");
    
    0 讨论(0)
提交回复
热议问题