Changing locale programmatically not working in some devices

后端 未结 2 1439
-上瘾入骨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: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");
    

提交回复
热议问题