Mixalis Mixalis - 2 years ago 132
Java Question

Change languange in android studio

I try to learn how to program in android studio and i am currently in the second tutorial about how to change languange by localizing.
When i try to create a second strings.xml file inside the folder values_el it say me i cant cause names should be unique.
I try to copy the original strings.xml file from values folder to the new values_el folder, i translate the messages but nothing happens.
Also i try to right click the original strings.xml file and i press the translate option and i translate them from there but nothing happens again.
When i run the app in my phone the languange is english in both of the ways i try above.
My phone languange is Greek but the letters of my program is english.

So here is 2 questions.
First why the languange do not change in my phone?
Second is there a way to change the languange of my app by pressing a button while i open it? Some games i play from google play have the option to choise your languange while before you start the game.
Sorry about my english if you dont understant something i say please let me know so i try to explain it better with google translate help.
Thank for your time anyway.

Thats the code i run

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:text="@string/edit_message" />


android:onClick="testActivity" />


Answer Source

Why dont you use the easy way through the IDE?

  1. Open your strings.xml file
  2. Click the Open Editor link as seen below

enter image description here

  1. Add the locales you want to add translations for by selecting like this

enter image description here

  1. This will create the right file for you without you needing to worry about the file name

  2. You dont need to open each strings.xml to put the localized strings. Do it right from this strings.xml editor.

Coming to your second question: The local on app will be the locale selected on device in the device settings. If you have not localized for the device locale it will fall back to the main strings.xml under res/values.

To force a locale in your app irrespective of the device's locale:

Add the following method in your activity class and call it in onCreate

private void setLanguageForApp(String language){

    String languageToLoad  = language; //pass the language code as param
    Locale locale;
        locale = Locale.getDefault();
    else {
        locale = new Locale(languageToLoad);
    Configuration config = new Configuration();
    config.locale = locale;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download