Changing Locale within the app itself

前端 未结 6 1788
遇见更好的自我
遇见更好的自我 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:57

    After a good night of sleep, I found the answer on the Web (a simple Google search on the following line "getBaseContext().getResources().updateConfiguration(mConfig, getBaseContext().getResources().getDisplayMetrics());"), here it is :

    link text => this link also shows screenshots of what is happening !

    Density was the issue here, I needed to have this in the AndroidManifest.xml

    
    

    The most important is the android:anyDensity =" true ".

    Don't forget to add the following in the AndroidManifest.xml for every activity (for Android 4.1 and below):

    android:configChanges="locale"
    

    This version is needed when you build for Android 4.2 (API level 17) explanation here:

    android:configChanges="locale|layoutDirection"
    

提交回复
热议问题