本文整理匯總了Java中android.content.res.Configuration.setLocales方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.setLocales方法的具體用法?Java Configuration.setLocales怎麽用?Java Configuration.setLocales使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Configuration
的用法示例。
在下文中一共展示了Configuration.setLocales方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: wrap
import android.content.res.Configuration; //導入方法依賴的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.content.res.Configuration; //導入方法依賴的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.content.res.Configuration; //導入方法依賴的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.content.res.Configuration; //導入方法依賴的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);
}