当前位置: 首页>>代码示例>>Java>>正文


Java Context.createConfigurationContext方法代码示例

本文整理汇总了Java中android.content.Context.createConfigurationContext方法的典型用法代码示例。如果您正苦于以下问题:Java Context.createConfigurationContext方法的具体用法?Java Context.createConfigurationContext怎么用?Java Context.createConfigurationContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.content.Context的用法示例。


在下文中一共展示了Context.createConfigurationContext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: wrap

import android.content.Context; //导入方法依赖的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);
}
 
开发者ID:qqq3,项目名称:inventum,代码行数:27,代码来源:InventumContextWrapper.java

示例2: wrap

import android.content.Context; //导入方法依赖的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);
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:27,代码来源:AppLocale.java

示例3: loadMmsConfig

import android.content.Context; //导入方法依赖的package包/类
private static MmsConfig loadMmsConfig(Context context, int subscriptionId) {
  if (subscriptionId != -1 && Build.VERSION.SDK_INT >= 24) {
    Optional<SubscriptionInfoCompat> subscriptionInfo = new SubscriptionManagerCompat(context).getActiveSubscriptionInfo(subscriptionId);

    if (subscriptionInfo.isPresent()) {
      Configuration configuration = context.getResources().getConfiguration();
      configuration.mcc = subscriptionInfo.get().getMcc();
      configuration.mnc = subscriptionInfo.get().getMnc();

      Context subcontext = context.createConfigurationContext(configuration);
      return new MmsConfig(subcontext, subscriptionId);
    }
  }

  return new MmsConfig(context, subscriptionId);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:MmsConfigManager.java

示例4: wrap

import android.content.Context; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static ContextWrapper wrap(Context context, String language) {
    Configuration config = context.getResources().getConfiguration();
    Locale sysLocale = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        sysLocale = getSystemLocale(config);
    } else {
        sysLocale = getSystemLocaleLegacy(config);
    }
    if (!language.equals("") && !sysLocale.getLanguage().equals(language)) {
        Locale locale = new Locale(language);
        Locale.setDefault(locale);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            setSystemLocale(config, locale);
        } else {
            setSystemLocaleLegacy(config, locale);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            context = context.createConfigurationContext(config);
        } else {
            context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
        }
    }
    return new MyContextWrapper(context);
}
 
开发者ID:hosamazzam,项目名称:AndroidChangeLanguage,代码行数:26,代码来源:MyContextWrapper.java

示例5: changeLocale

import android.content.Context; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static void changeLocale(String locale) {
    Context context = InstrumentationRegistry.getInstrumentation()
            .getTargetContext();

    Resources res = context.getApplicationContext().getResources();
    Configuration config = res.getConfiguration();


    config.setLocale(new Locale(locale));
    if (SDK_INT >= 25) {
        context.createConfigurationContext(config);
    } else {
        res.updateConfiguration(config, res.getDisplayMetrics());
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:17,代码来源:SwitchLocaleTest.java

示例6: wrap

import android.content.Context; //导入方法依赖的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);
}
 
开发者ID:ansarisufiyan777,项目名称:Show_Chat,代码行数:27,代码来源:ShowChatContextWrapper.java

示例7: updateResources

import android.content.Context; //导入方法依赖的package包/类
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;
}
 
开发者ID:YarikSOffice,项目名称:LanguageTest,代码行数:16,代码来源:LocaleManager.java

示例8: updateResources

import android.content.Context; //导入方法依赖的package包/类
private static void updateResources(Context context, String language) {
    Locale locale = getLocale(language);
    Locale.setDefault(locale);
    Configuration configuration = context.getResources().getConfiguration();
    configuration.setLocale(locale);
    context.createConfigurationContext(configuration);
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:8,代码来源:AppHelper.java

示例9: updateResources

import android.content.Context; //导入方法依赖的package包/类
public static Context updateResources(Context context, Locale locale) {
    Locale.setDefault(locale);
    Resources resources = context.getResources();
    Configuration configuration = resources.getConfiguration();
    configuration.setLayoutDirection(locale);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        configuration.setLocale(locale);
        return context.createConfigurationContext(configuration);
    } else {
        configuration.locale = locale;
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());
        return context;
    }
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:15,代码来源:LocaleUtils.java

示例10: updateResources

import android.content.Context; //导入方法依赖的package包/类
@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);
}
 
开发者ID:joaomneto,项目名称:TitanCompanion,代码行数:12,代码来源:LocaleHelper.java

示例11: updateResources

import android.content.Context; //导入方法依赖的package包/类
@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);

    return context.createConfigurationContext(configuration);
}
 
开发者ID:jayakrishnan-pm,项目名称:Change-Language-AtRuntime,代码行数:11,代码来源:LocaleHelper.java

示例12: applyLanguageForContext

import android.content.Context; //导入方法依赖的package包/类
/**
 * Setting {@link Locale} for {@link Context}.
 */
@NonNull
public static Context applyLanguageForContext(@NonNull Context context, @NonNull Locale locale) {
    Resources resources = context.getResources();
    Configuration config = resources.getConfiguration();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        config.setLocale(locale);
        return context.createConfigurationContext(config);
    } else {
        config.locale = locale;
        resources.updateConfiguration(config, resources.getDisplayMetrics());
        return context;
    }
}
 
开发者ID:WeiXinqiao,项目名称:Recognize-it,代码行数:17,代码来源:AlbumUtils.java

示例13: getLocaleConfiguredContext

import android.content.Context; //导入方法依赖的package包/类
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
private Context getLocaleConfiguredContext(Context context, Locale locale) {
    Configuration conf = context.getResources().getConfiguration();
    conf.setLocale(locale);
    return context.createConfigurationContext(conf);
}
 
开发者ID:franmontiel,项目名称:LocaleChanger,代码行数:7,代码来源:AppLocaleChanger.java

示例14: wrapConfiguration

import android.content.Context; //导入方法依赖的package包/类
public static Context wrapConfiguration(@NonNull final Context context, @NonNull final Configuration config) {
    return context.createConfigurationContext(config);
}
 
开发者ID:JarvanMo,项目名称:MarsBootProject,代码行数:4,代码来源:ConfigurationWrapper.java


注:本文中的android.content.Context.createConfigurationContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。