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);直接使用财产