0

I have two different strings.xml for multi-language app. Where can I set that I want to use English strings.xml file independent of phone locale language always but use Chinese language only in case when on splash screen we have chosen it?

3
  • Have you read this support-languages Commented Jan 2, 2020 at 11:30
  • Do you want to support choosing language in your app? Commented Jan 2, 2020 at 11:39
  • @Bracadabra yes, simply I need to open app with strings.xml that will conform to selected on start screen language. Commented Jan 2, 2020 at 12:09

1 Answer 1

1

To support language setting in your application you need to change current configuration and restart activity to reload all resources. You can change current configuration like this:

void changeLanguage(Context context, String language) {
    final Locale locale = new Locale(language);
    Locale.setDefault(locale);

    final Resources res = context.getResources();
    final Configuration config = new Configuration(res.getConfiguration());
    config.setLocale(locale);
    res.updateConfiguration(config, res.getDisplayMetrics());
}

And then don't forget to recreate your activity activity.recreate(); or reload your resources manually.

Also you need to set your locale on every process start. You can do it in application onCreate:

public void YourApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        changeLanguage(this, getLanguageSettingsFromPreferences());
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.