Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何固定线头';s";配置中的[deprecation]区域设置已被弃用;警告_Android_Locale_Deprecated_Lint_Android 7.0 Nougat - Fatal编程技术网

Android 如何固定线头';s";配置中的[deprecation]区域设置已被弃用;警告

Android 如何固定线头';s";配置中的[deprecation]区域设置已被弃用;警告,android,locale,deprecated,lint,android-7.0-nougat,Android,Locale,Deprecated,Lint,Android 7.0 Nougat,希望这不是与不推荐的context.getResources().getConfiguration().locale调用有关的许多其他问题的重复,因为我已经修复了它 如何消除以下代码的Lint警告: public static String toDateString(Context context, Date date) { DateFormat format = Build.VERSION.SDK_INT >= 24 ? DateFormat.getDat

希望这不是与不推荐的
context.getResources().getConfiguration().locale
调用有关的许多其他问题的重复,因为我已经修复了它

如何消除以下代码的Lint警告:

public static String toDateString(Context context, Date date)
{
    DateFormat format = Build.VERSION.SDK_INT >= 24 ?
            DateFormat.getDateInstance(DateFormat.MEDIUM, context.getResources().getConfiguration().getLocales().get(0)) :
            DateFormat.getDateInstance(DateFormat.MEDIUM, context.getResources().getConfiguration().locale);
    return format.format(date);
}

您不应该直接使用属性


请参见

首先检查当前版本并使用不推荐的版本。试试这个

    Locale locale;
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
      locale = this.getResources().getConfiguration().getLocales().get(0);
    } else{
      locale = this.getResources().getConfiguration().locale;
    }
  • 您只需使用
    Locale.getDefault()

  • 您的第一个解决方案与我的代码相同。我现在正在检查第二个。您可以尝试查看更多详细信息
    Resources=context.getResources();语言环境=Build.VERSION.SDK\u INT>=Build.VERSION\u code.N?resources.getConfiguration().getLocales().getFirstMatch(resources.getAssets().getLocales()):resources.getConfiguration().locale这就是我为API>=24所做的。在您的链接中:“如果只需要主语言环境,那么getLocales().get(0)现在是首选的访问器。”我的意思是我不使用它directly@PIXP我注意到了第二个分支:DateFormat.getDateInstance(DateFormat.MEDIUM,context.getResources().getConfiguration().locale);直接使用财产