Introduction
This article explains how your application can support various languages in Android using Android Studio.
This application supports the two languages, English and Spanish. So when you start the application its layout contains the English language because it is already set in the locale of the emulator. To start your application in the Spanish language you need to set the Spanish inside the locale. After doing that when you start your application its layout uses the Spanish language.
When we create the project there is string.xml file inside the res->values. It is created by default by the system when you create the project.This file contains:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="app_name">SupportingDifferentLanguages</string>
- <string name="action_settings">Settings</string>
- <string name="enter_name">Enter Name</string>
- <string name="enter_age">Enter Age</string>
- <string name="enter">Submit</string>
- </resources>
It is set by default in your application XML file when you create the project. So to make your application support a different language you need to do this.
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="enter_name">ingrese el nombre</string>
- <string name="enter_age">entrar en la edad</string>
- <string name="enter">presentar</string>
- </resources>
You will set the language text in your layout by writing this in your MainActivity.
- TextView textview=new TextView(this);
- TextView textview2=new TextView(this);
- Button button=new Button(this);
- textview.setText(R.string.enter_name);
- textview2.setText(R.string.enter_age);
- button.setText(R.string.enter);


Kashif SohailPosted Mar 26, 2016, 11:28 PM
Nice