How to set default language for Android app?

I created an application in two languages. The second (English) is used when the default user system language is English. If it is not, then the first is used.

I want to set the second language (English) as the DEFAULT language, this means that when the user opens my application and his system language is not the first, neither English, English will be displayed as standard.

I tried:

Locale locale = new Locale("en_US"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; context.getApplicationContext.getResources().updateConfiguration(config, null); 

But the error "context cannot be resolved" every time. Is this piece of code correct or ...?

+6
source share
3 answers

Good,

to make everything clear, I realized that res/values is the DEFAULT directory, and the rest is just "in the case of the language." So all I had to do was switch the English to / res / values ​​and the other language to res/values-es

+5
source

You must define all the languages ​​you support using the res folders, i.e. res/values , res/values-en , res/values-fr . The system will take care of everything else, you do not need any code.

0
source

If you work, you can:

this.getApplicationContext().getResources().updateConfiguration(config, null);

... fix your mistake. Otherwise, you need to go into context.

Make sure you copy the brackets at the end of getApplicationContext() . You did not do this in your code.

0
source

Source: https://habr.com/ru/post/969783/


All Articles