本文整理汇总了Java中android.os.LocaleList.setDefault方法的典型用法代码示例。如果您正苦于以下问题:Java LocaleList.setDefault方法的具体用法?Java LocaleList.setDefault怎么用?Java LocaleList.setDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.LocaleList
的用法示例。
在下文中一共展示了LocaleList.setDefault方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrap
import android.os.LocaleList; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString(Constants.PREF_APP_LANGUAGE, "");
Locale locale = StringUtils.getLocale(lang);
locale = (locale == null) ? Locale.getDefault() : locale;
Configuration configuration = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList localeList = new LocaleList(locale);
LocaleList.setDefault(localeList);
Locale.setDefault(locale);
configuration.setLocale(locale);
configuration.setLocales(localeList);
context = context.createConfigurationContext(configuration);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLocale(locale);
context = context.createConfigurationContext(configuration);
} else {
configuration.locale = locale;
context.getResources().updateConfiguration(configuration, null);
}
return new InventumContextWrapper(context);
}
示例2: wrap
import android.os.LocaleList; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context, Locale newLocale)
{
final Resources res = context.getResources();
final Configuration configuration = res.getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
{
configuration.setLocale(newLocale);
LocaleList localeList = new LocaleList(newLocale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);
context = context.createConfigurationContext(configuration);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
{
configuration.setLocale(newLocale);
context = context.createConfigurationContext(configuration);
}
else
{
configuration.locale = newLocale;
res.updateConfiguration(configuration, res.getDisplayMetrics());
}
return new ContextWrapper(context);
}
示例3: setLocale
import android.os.LocaleList; //导入方法依赖的package包/类
public static void setLocale(@NonNull Context context) {
Locale locale = Preferences.get(context).getCurrentLocale();
Locale.setDefault(locale);
Configuration configuration = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList.setDefault(new LocaleList(locale));
configuration.setLocales(new LocaleList(locale));
configuration.setLocale(locale);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLocale(locale);
} else {
configuration.locale = locale;
}
//Todo:
// Find out a solution to use context.createConfigurationContext(configuration);
// It breaks onConfigurationChanged()
// Still can't find a way to fix that
// No other options, better use deprecated code for now
context.getResources().updateConfiguration(configuration, context.getResources().getDisplayMetrics());
}
示例4: wrap
import android.os.LocaleList; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String lang = prefs.getString(Constants.PREF_APP_LANGUAGE, "");
Locale locale = StringUtils.getLocale(lang);
locale = (locale == null) ? Locale.getDefault() : locale;
Configuration configuration = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList localeList = new LocaleList(locale);
LocaleList.setDefault(localeList);
Locale.setDefault(locale);
configuration.setLocale(locale);
configuration.setLocales(localeList);
context = context.createConfigurationContext(configuration);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
configuration.setLocale(locale);
context = context.createConfigurationContext(configuration);
} else {
configuration.locale = locale;
context.getResources().updateConfiguration(configuration, null);
}
return new ShowChatContextWrapper(context);
}
示例5: wrap
import android.os.LocaleList; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
Locale newLocale;
Resources res = context.getResources();
Configuration configuration = res.getConfiguration();
if (Tools.getBoolean("forceenglish", false, context))
newLocale = new Locale("en_US");
else
newLocale = new Locale(Tools.sysLocale());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(newLocale);
LocaleList localeList = new LocaleList(newLocale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);
context = context.createConfigurationContext(configuration);
} else { //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
configuration.setLocale(newLocale);
context = context.createConfigurationContext(configuration);
}
return new ContextWrapper(context);
}
示例6: wrap
import android.os.LocaleList; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context) {
Locale newLocale;
Resources res = context.getResources();
Configuration configuration = res.getConfiguration();
if (Utils.getBoolean("forceenglish", false, context))
newLocale = new Locale("en_US");
else
newLocale = new Locale(Utils.sysLocale());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
configuration.setLocale(newLocale);
LocaleList localeList = new LocaleList(newLocale);
LocaleList.setDefault(localeList);
configuration.setLocales(localeList);
context = context.createConfigurationContext(configuration);
} else { //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
configuration.setLocale(newLocale);
context = context.createConfigurationContext(configuration);
}
return new ContextWrapper(context);
}
示例7: applyLocalizationContext
import android.os.LocaleList; //导入方法依赖的package包/类
public static Context applyLocalizationContext(Context baseContext) {
Locale baseLocale = LocalizationUtility.getLocaleFromConfiguration(baseContext.getResources().getConfiguration());
Locale currentLocale = LanguageSetting.getLanguage(baseContext);
if (!baseLocale.toString().equalsIgnoreCase(currentLocale.toString())) {
LocalizationContext context = new LocalizationContext(baseContext);
Configuration config = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
config.setLocale(currentLocale);
LocaleList localeList = new LocaleList(currentLocale);
LocaleList.setDefault(localeList);
config.setLocales(localeList);
return context.createConfigurationContext(config);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(currentLocale);
return context.createConfigurationContext(config);
} else {
return context;
}
} else {
return baseContext;
}
}
示例8: attachBaseContext
import android.os.LocaleList; //导入方法依赖的package包/类
public Context attachBaseContext(Context context) {
Locale locale = LanguageSetting.getLanguage(context);
Configuration config = context.getResources().getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
config.setLocale(locale);
LocaleList localeList = new LocaleList(locale);
LocaleList.setDefault(localeList);
config.setLocales(localeList);
return context.createConfigurationContext(config);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
config.setLocale(locale);
return context.createConfigurationContext(config);
} else {
return context;
}
}