首页 > 解决方案 > 在不使用 @SuppressWarnings 的情况下解决 lint 已弃用的警告

问题描述

我有一种感觉,我可以在不强行压制它的情况下处理上述警告。但是,这似乎不起作用:

static Context updateResources(Context context) {
        Resources resources = context.getResources();
        Configuration config = new Configuration(resources.getConfiguration());
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        String lang = preferences.getString(Constants.PREF_KEY_LOCALE_OVERRIDE, Constants.PREF_VALUE_LOCALE_SYSTEM);
        Locale locale = new Locale(lang);

        if (Build.VERSION.SDK_INT >= 17) {
            config.setLocale(locale);
            context = context.createConfigurationContext(config);
        } else {

        //this is where the warning is at: 
            config.locale = locale;
            resources.updateConfiguration(config, null);
        }
        return context;
}

如何清除此警告?

警告:配置中的 [deprecation] 语言环境已被弃用

config.locale = 语言环境;

标签: androidlocaledeprecatedlintdeprecation-warning

解决方案


推荐阅读