android.content.Context.createConfigurationContext()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(209)

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

Context.createConfigurationContext介绍

暂无

代码示例

代码示例来源:origin: oasisfeng/condom

@RequiresApi(JELLY_BEAN_MR1) @Override public Context createConfigurationContext(Configuration overrideConfiguration) {
  return mBase.createConfigurationContext(overrideConfiguration);
}

代码示例来源: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: robolectric/robolectric

@Test
@Config(minSdk = JELLY_BEAN_MR1)
public void createConfigurationContext() {
 Configuration configuration = new Configuration(context.getResources().getConfiguration());
 configuration.mcc = 234;
 Context configurationContext = context.createConfigurationContext(configuration);
 assertThat(configurationContext).isNotNull();
}

代码示例来源:origin: Trumeet/MiPushFramework

@RequiresApi(JELLY_BEAN_MR1) @Override public Context createConfigurationContext(Configuration overrideConfiguration) {
  return mBase.createConfigurationContext(overrideConfiguration);
}

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

@TargetApi(Build.VERSION_CODES.N)
private static Context updateResourcesLocale(Context context, Locale locale) {
  Configuration configuration = context.getResources().getConfiguration();
  configuration.setLocale(locale);
  return context.createConfigurationContext(configuration);
}

代码示例来源:origin: westnordost/StreetComplete

private Resources getResources(Locale locale)
  {
    Configuration configuration = new Configuration(applicationContext.getResources().getConfiguration());
    configuration.setLocale(locale);
    return applicationContext.createConfigurationContext(configuration).getResources();
  }
}

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

private static Context updateResources(Context context, String language) {
  Locale locale = new Locale(language);
  Locale.setDefault(locale);
  Resources res = context.getResources();
  Configuration config = new Configuration(res.getConfiguration());
  if (Build.VERSION.SDK_INT >= 17) {
    config.setLocale(locale);
    context = context.createConfigurationContext(config);
  } else {
    config.locale = locale;
    res.updateConfiguration(config, res.getDisplayMetrics());
  }
  return 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: VREMSoftwareDevelopment/WiFiAnalyzer

@TargetApi(Build.VERSION_CODES.N)
@NonNull
private static Context createContextNougat(@NonNull Context context, @NonNull Locale newLocale) {
  Resources resources = context.getResources();
  Configuration configuration = resources.getConfiguration();
  configuration.setLocale(newLocale);
  return context.createConfigurationContext(configuration);
}

代码示例来源:origin: voroshkov/Chorus-RF-Laptimer

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void setContextToUse(Configuration configuration, Locale locale) {
  configuration.setLocale(locale);
  contextInUse = originalContext.createConfigurationContext(configuration);
}

代码示例来源:origin: AndBible/and-bible

@TargetApi(Build.VERSION_CODES.N)
  @Override
  public Context changeLocale(Context context, String language) {
    logger.debug("Update resources N plus");

    Locale locale = Locale.forLanguageTag(language);
    Locale.setDefault(locale);

    Configuration configuration = context.getResources().getConfiguration();
    configuration.setLocale(locale);

    return context.createConfigurationContext(configuration);
  }
}

代码示例来源:origin: gunhansancar/ChangeLanguageExample

@TargetApi(Build.VERSION_CODES.N)
private static Context updateResources(Context context, String language) {
  Locale locale = new Locale(language);
  Locale.setDefault(locale);
  Configuration configuration = context.getResources().getConfiguration();
  configuration.setLocale(locale);
  configuration.setLayoutDirection(locale);
  return context.createConfigurationContext(configuration);
}

代码示例来源:origin: dsolonenko/financisto

private static Context switchLocale(Context context, Locale locale) {
  Locale.setDefault(locale);
  Resources res = context.getResources();
  Configuration config = new Configuration(res.getConfiguration());
  config.setLocale(locale);
  context = context.createConfigurationContext(config);
  Log.i("MyPreferences", "Switching locale to " + config.locale.getDisplayName());
  return context;
}

代码示例来源:origin: finddreams/AndroidMultiLanguage

@TargetApi(Build.VERSION_CODES.N)
  private static Context createConfigurationResources(Context context) {
    Resources resources = context.getResources();
    Configuration configuration = resources.getConfiguration();
    Locale locale=getInstance().getLanguageLocale();
    configuration.setLocale(locale);
    return context.createConfigurationContext(configuration);
  }
}

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

private static Context updateResources(Context context, Locale locale) {
  Locale.setDefault(locale);
  Resources res = context.getResources();
  Configuration config = new Configuration(res.getConfiguration());
  if (Build.VERSION.SDK_INT >= 17) {
    config.setLocale(locale);
    context = context.createConfigurationContext(config);
  } else {
    config.locale = locale;
    res.updateConfiguration(config, res.getDisplayMetrics());
  }
  return context;
}

代码示例来源:origin: YarikSOffice/LanguageTest

private Context updateResources(Context context, String language) {
  Locale locale = new Locale(language);
  Locale.setDefault(locale);
  Resources res = context.getResources();
  Configuration config = new Configuration(res.getConfiguration());
  if (Utility.isAtLeastVersion(JELLY_BEAN_MR1)) {
    config.setLocale(locale);
    context = context.createConfigurationContext(config);
  } else {
    config.locale = locale;
    res.updateConfiguration(config, res.getDisplayMetrics());
  }
  return context;
}

代码示例来源:origin: esafirm/android-image-picker

public static Context updateResources(Context context) {
    Locale locale = new Locale(getLanguage());
    Locale.setDefault(locale);

    Resources res = context.getResources();
    Configuration config = new Configuration(res.getConfiguration());
    if (Build.VERSION.SDK_INT >= 17) {
      config.setLocale(locale);
      context = context.createConfigurationContext(config);
    } else {
      config.locale = locale;
      res.updateConfiguration(config, res.getDisplayMetrics());
    }
    return 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: Sparker0i/Weather

@SuppressWarnings("deprecation")
  private void updateConfiguration(Configuration config) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      getBaseContext().createConfigurationContext(config);
    } else {
      getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
    }
  }
}

相关文章

Context类方法