List of usage examples for android.content.res Resources updateConfiguration
@Deprecated public void updateConfiguration(Configuration config, DisplayMetrics metrics)
From source file:Main.java
public static void setLanguage(Context context, String language) { Locale locale;/*from ww w.j a va 2s. co m*/ 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()); }
From source file:Main.java
public static void normalFontSize(Resources resource) { Configuration configuration = resource.getConfiguration(); configuration.fontScale = 1f;//from w w w . j a va2s . c om resource.updateConfiguration(configuration, resource.getDisplayMetrics()); }
From source file:Main.java
public static void updateResources(Context context, String language) { //set the language of the app Locale locale = new Locale(language); Locale.setDefault(locale);//from w w w.j av a 2 s.c o m Resources resources = context.getResources(); Configuration configuration = resources.getConfiguration(); configuration.locale = locale; resources.updateConfiguration(configuration, resources.getDisplayMetrics()); }
From source file:Main.java
private static void updateResources(Context context, String language) { Locale locale = new Locale(language); Locale.setDefault(locale);//w w w .j av a 2 s . co m Resources resources = context.getResources(); Configuration configuration = resources.getConfiguration(); configuration.locale = locale; resources.updateConfiguration(configuration, resources.getDisplayMetrics()); }
From source file:Main.java
private static void updateResources(Context context, String language) { Locale locale = new Locale(language); Locale.setDefault(locale);//w w w .j a va2 s .com Resources resources = context.getResources(); Configuration configuration = new Configuration(resources.getConfiguration()); configuration.locale = locale; resources.updateConfiguration(configuration, resources.getDisplayMetrics()); }
From source file:Main.java
public static void setLocale(Context ctx, String lang) { Locale locale;//w w w . j a v a2s.c o m /* if(lang.equals("zh") || lang.equals("zh-HK") || lang.equals("zh-")) locale = Locale.TRADITIONAL_CHINESE; else if(lang.equals("zh-CN")) locale = Locale.SIMPLIFIED_CHINESE; else locale = new Locale(lang);*/ locale = new Locale(lang); Resources res = ctx.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); Configuration conf = res.getConfiguration(); conf.locale = locale; res.updateConfiguration(conf, dm); }
From source file:Main.java
/** * Sets the system locale for this process. * * @param res the resources to use. Pass current resources. * @param newLocale the locale to change to. * @return the old locale.//w ww . j ava 2 s .c om */ public static Locale setSystemLocale(final Resources res, final Locale newLocale) { final Configuration conf = res.getConfiguration(); final Locale saveLocale = conf.locale; conf.locale = newLocale; res.updateConfiguration(conf, res.getDisplayMetrics()); return saveLocale; }
From source file:Main.java
/** * Set default language/*ww w.j a v a2s . c om*/ * * @param act * @param defLanguage */ public static void setDefaultLanguage(Activity act, String defLanguage) { if (defLanguage != null) { // Change locale settings in the app. Resources res = act.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = new Locale(defLanguage); res.updateConfiguration(conf, dm); } }
From source file:Main.java
/** * @return a localized version of the text resource specified by resId *//* ww w .j av a 2s . c o m*/ static CharSequence getTextForLocale(Context context, Locale locale, int resId) { final Resources res = context.getResources(); final Configuration config = res.getConfiguration(); final Locale prevLocale = config.locale; try { config.locale = locale; res.updateConfiguration(config, null); return res.getText(resId); } finally { config.locale = prevLocale; res.updateConfiguration(config, null); } }
From source file:Main.java
public static void updateApplicationResourceLocale(Context context, Locale locale) { Resources resources = context.getResources(); Configuration configuration = resources.getConfiguration(); if (!configuration.locale.equals(locale)) { android.util.DisplayMetrics displaymetrics = resources.getDisplayMetrics(); configuration.locale = locale;/*from w ww . j ava2 s. c o m*/ resources.updateConfiguration(configuration, displaymetrics); Resources.getSystem().updateConfiguration(configuration, displaymetrics); } }