MultiLanguageSupportedAndroid

Success with mobile apps is often a numbers game — the more users, the more successful an app will be. Some of the ways to increase users, such as localizing to other languages, require advance planning. If an app has been prepared for localization, then translating it to several new languages can be an easy way to make the app accessible to a huge number of new customers.

1. MainActivity.java

package com.tutorialsee;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Locale;

public class MainActivity extends Activity {

EditText ET_eamil,ET_password;
TextView TV_Hindi,TV_English,TV_French;
Locale mylocale;

@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);

ET_eamil=(EditText)findViewById(R.id.emailid);
ET_password=(EditText)findViewById(R.id.password);
//Change Hint color text
ET_eamil.setHintTextColor(getResources().getColor(R.color.white));
ET_password.setHintTextColor(getResources().getColor(R.color.white));

TV_Hindi=(TextView)findViewById(R.id.TVHindi);
TV_English=(TextView)findViewById(R.id.TVEnglish);
TV_French=(TextView)findViewById(R.id.TVFrench);

//Set Hindi Language
TV_Hindi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"Hindi Language",Toast.LENGTH_SHORT).show();
setLanguage("hi");
}
});

//Set English Language
TV_English.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"English Language",Toast.LENGTH_SHORT).show();
setLanguage("en");
}
});

//Set French Language
TV_French.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this,"French Language",Toast.LENGTH_SHORT).show();
setLanguage("fr");
}
});
}

//Change language Method
protected void setLanguage(String language){
mylocale=new Locale(language);
Resources resources=getResources();
DisplayMetrics dm=resources.getDisplayMetrics();
Configuration conf= resources.getConfiguration();
conf.locale=mylocale;
resources.updateConfiguration(conf,dm);
Intent refreshIntent=new Intent(MainActivity.this,MainActivity.class);
finish();
startActivity(refreshIntent);
}

}

2. activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00BCD4"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/welcome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:padding="10dp"
        android:text="@string/welcome"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#ffffff"
        android:textSize="45sp"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/emailid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="15dp"
        android:hint="@string/email"
        android:textColor="#FAFAFA" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="15dp"
        android:hint="@string/password"
        android:textColor="#FAFAFA" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:text="@string/login"
        android:background="#FAFAFA"
        android:textColor="#0097A7" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        android:text="@string/signup"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffff" />

    <LinearLayout
        android:id="@+id/Language_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginBottom="0dp"
        android:layout_marginTop="50dp"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/TVHindi"
            android:layout_width="wrap_content"
            android:layout_height="56dp"
            android:padding="10dp"
            android:text="@string/hi_language"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#ffffff"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/TVEnglish"
            android:layout_width="wrap_content"
            android:layout_height="56dp"
            android:padding="10dp"
            android:text="@string/en_language"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#ffffff"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/TVFrench"
            android:layout_width="wrap_content"
            android:layout_height="56dp"
            android:padding="10dp"
            android:text="@string/fr_language"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#ffffff"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>