android.content.res.Configuration.setLocales()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中android.content.res.Configuration.setLocales()方法的一些代码示例,展示了Configuration.setLocales()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.setLocales()方法的具体详情如下:
包路径:android.content.res.Configuration
类名称:Configuration
方法名:setLocales

Configuration.setLocales介绍

暂无

代码示例

代码示例来源:origin: seven332/EhViewer

public static ContextLocalWrapper wrap(Context context, Locale newLocale) {
  Resources res = context.getResources();
  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 ContextLocalWrapper(context);
 }
}

代码示例来源:origin: ukanth/afwall

public static ContextWrapper wrap(Context context, Locale newLocale) {
  Resources res = context.getResources();
  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);
}

代码示例来源:origin: 8enet/AppOpsX

@TargetApi(Build.VERSION_CODES.N)
private static Context updateResources(Context context) {
 Resources resources = context.getResources();
 Locale locale = getLocaleByLanguage(context);
 Configuration configuration = resources.getConfiguration();
 configuration.setLocale(locale);
 configuration.setLocales(new LocaleList(locale));
 return context.createConfigurationContext(configuration);
}

代码示例来源:origin: captain-miao/MultiLanguagesSwitch

@TargetApi(Build.VERSION_CODES.N)
    private static Context updateResources(Context context, String language) {
    Resources resources = context.getResources();
    Locale locale = AppLanguageUtils.getLocaleByLanguage(language);

      Configuration configuration = resources.getConfiguration();
      configuration.setLocale(locale);
      configuration.setLocales(new LocaleList(locale));
      return context.createConfigurationContext(configuration);
    }
}

代码示例来源:origin: MichaelJokAr/MultiLanguages

/**
 * 设置语言类型
 */
public static void setApplicationLanguage(Context context) {
  Resources resources = context.getApplicationContext().getResources();
  DisplayMetrics dm = resources.getDisplayMetrics();
  Configuration config = resources.getConfiguration();
  Locale locale = getSetLanguageLocale(context);
  config.locale = locale;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    LocaleList localeList = new LocaleList(locale);
    LocaleList.setDefault(localeList);
    config.setLocales(localeList);
    context.getApplicationContext().createConfigurationContext(config);
    Locale.setDefault(locale);
  }
  resources.updateConfiguration(config, dm);
}

代码示例来源:origin: bigsinger/fakegps

public static void changeLocalLanguage(Context context, Locale locale) {
  Resources resources = context.getResources();
  DisplayMetrics dm = resources.getDisplayMetrics();
  Configuration config = resources.getConfiguration();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    LocaleList localeList = new LocaleList(locale);
    LocaleList.setDefault(localeList);
    config.setLocales(localeList);
    resources.updateConfiguration(config,dm);
  } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    config.setLocale(locale);
    resources.updateConfiguration(config, dm);
  } else {
    config.locale = locale;
    resources.updateConfiguration(config, dm);
  }
}

代码示例来源:origin: morogoku/MTweaks-KernelAdiutorMOD

public static ContextWrapper wrap(Context context, Locale newLocale) {
  Resources res = context.getResources();
  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);
}

代码示例来源:origin: fgl27/isu

@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);
}

代码示例来源:origin: mkulesh/microMathematics

@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);
  }
}

相关文章