0

I am trying to change the language of my Android app with no success. I have:

/res/ . values/ . . string.xml . . values-es/ . . . strings.xml 

Both strings files contains the same but the content is translated according to the language code. The default language is english but I want to do some tests and use the spanish language.

I use the code written in this previous question: Change app language programmatically in Android

Here is my LoginActivity(launcher)'s onCreate method:

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setting default screen to login.xml setContentView(R.layout.login); Resources res = getBaseContext().getResources(); // Change locale settings in the app. DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = new Locale("es"); res.updateConfiguration(conf, dm); TextView registerScreen = (TextView) findViewById(R.id.link_to_register); // Listening to register new account link registerScreen.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Switching to Register screen Intent i = new Intent(getApplicationContext(), RegisterActivity.class); startActivity(i); } }); Button mainMenu = (Button) findViewById(R.id.btnLogin); // Listening to register new account link mainMenu.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Switching to Register screen Intent i = new Intent(getApplicationContext(), MainMenuActivity.class); startActivity(i); } }); } 

My target is Android 4.4.

However, this is not working on my Nexus 4 - Android 4.4, it always uses English language.

2

1 Answer 1

1

The values-es folder should be on the same level as the values folder. Your example above looks like you have values-es inside the values folder.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.