Disable localization in Android application

后端 未结 3 584
Happy的楠姐
Happy的楠姐 2021-01-06 03:59

Is there any way to disable localization in an Android application? It must use only English strings. We have library projects with French localized strings. Some apps that

3条回答
  •  无人及你
    2021-01-06 04:36

    Android's normal behavior is that you define a given language only if you support it. For french this would be values-fr/strings.xml. If you don't want to support french don't include the strings.xml for french and it will fall back to the strings.xml in the values folder

    http://developer.android.com/guide/topics/resources/localization.html

    If you don't have control over the provided strings or if you want to dynamically set the locales to support you can override the default locale.

    http://developer.android.com/reference/java/util/Locale.html#setDefault(java.util.Locale)

    EDIT

    What I forgot to mention is that you have to update your configuration with the new config

    Configuration config = new Configuration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,getBaseContext().getResources().getDisplayMetrics());
    

提交回复
热议问题