You can change the language (locale) of the application programmatically using a simple function. You only need to implement a method similar to the one you have below, which receives a string as a parameter (for example, "en" for English, "es" for Spanish), where you can configure the locale for your application and update the current activities to reflect change. The language you have applied will not be changed until you manually change it.
public void setLocale(String lang) {
myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, AndroidLocalize.class);
startActivity(refresh);
finish();
}
Make sure you import the following packages:
import java.util.Locale;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.DisplayMetrics;
import android.content.res.Resources;
import android.content.res.Configuration;
Add also a manifest inside your activity tag android:configChanges="locale|orientation"
source
share