Android Context Set setLanguage(Context context, String language)

Here you can find the source of setLanguage(Context context, String language)

Description

set Language

Declaration

public static void setLanguage(Context context, String language) 

Method Source Code

//package com.java2s;
import java.util.Locale;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;

import android.text.TextUtils;

public class Main {
    public static void setLanguage(Context context, String language) {
        Locale locale;/*from w ww . j ava2s  . c om*/
        if (TextUtils.isEmpty(language)) {
            locale = Locale.getDefault();
        } else if (language.length() == 5 && language.charAt(2) == '_') {
            // language is in the form: en_US
            locale = new Locale(language.substring(0, 2),
                    language.substring(3));
        } else {
            locale = new Locale(language);
        }

        Configuration config = new Configuration();
        config.locale = locale;
        Resources resources = context.getResources();
        resources
                .updateConfiguration(config, resources.getDisplayMetrics());
    }
}

Related

  1. sendStopKey(Context c)
  2. setAppContext(Context context)
  3. setBaiduServiceEnabled(Context paramContext, boolean paramBoolean)
  4. setContext(Application app)
  5. setDefaultLocale(Context context, String locale)
  6. setProxy(Context ctx)
  7. setProxy(Context ctx, String host, int port)
  8. setRevokedPermissions(String packageName, String[] permissions, Context ctx)
  9. setWebkitProxyGingerbread(Context ctx, String host, int port)