Changing Locale within the app itself

前端 未结 6 1968
遇见更好的自我
遇见更好的自我 2020-11-22 01:31

My users can change the Locale within the app (they may want to keep their phone settings in English but read the content of my app in French, Dutch or any other language ..

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 01:52

    I couldn't used android:anyDensity="true" because objects in my game would be positioned completely different... seems this also does the trick:

    // creating locale
    Locale locale2 = new Locale(loc); 
    Locale.setDefault(locale2);
    Configuration config2 = new Configuration();
    config2.locale = locale2;
    
    // updating locale
    mContext.getResources().updateConfiguration(config2, null);
    

提交回复
热议问题