Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Change the locale language inside the app
public class App extends Application {
public void onCreate(){
LocaleUtils.setLocale(new Locale("iw"));
LocaleUtils.updateConfig(this, getBaseContext().getResources().getConfiguration());
public void onConfigurationChanged(Configuration newConfig) {
LocaleUtils.updateConfig(this, newConfig);
public class BaseActivity extends AppCompatActivity {
public BaseActivity() {
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import android.view.ContextThemeWrapper;
import java.util.Locale;
public class LocaleUtils {
public static final String LAN_SPANISH = "es";
public static final String LAN_PORTUGUESE = "pt";
public static final String LAN_ENGLISH = "en";
private static Locale sLocale;
public static void setLocale(Locale locale) {
sLocale = locale;
if(sLocale != null) {
public static void updateConfig(ContextThemeWrapper wrapper) {
if(sLocale != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Configuration configuration = new Configuration();
public static void updateConfig(Application app, Configuration configuration) {
if(sLocale != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
//Wrapping the configuration to avoid Activity endless loop
Configuration config = new Configuration(configuration);
config.locale = sLocale;
Resources res = app.getBaseContext().getResources();
res.updateConfiguration(config, res.getDisplayMetrics());

This comment has been minimized.

Copy link

@mchun mchun commented Feb 22, 2018

I followed this gist to implement changing language within app functionality. But recently I found that even if the font size is set in sp format, the font size doesn't change with the system font settings, unless I change BaseActivity back to AppCompatActivity....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment