How to change android app language without changing phone language?

后端 未结 1 640
感情败类
感情败类 2021-02-06 15:20

I want user to select a language inside the app. Once the language is selected, I want the strings to use the particular language.

If I change the phone language, then m

相关标签:
1条回答
  • 2021-02-06 15:43

    Try this

    public static void changeLang(Context context, String lang) {
        Locale myLocale = new Locale(lang);
        Locale.setDefault(myLocale);
        android.content.res.Configuration config = new android.content.res.Configuration();
        config.locale = myLocale;
        context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
    }
    

    Lang parameter should be "en" for English, "it" for Italian... After that you should restart your activity/fragment

    0 讨论(0)
提交回复
热议问题